Hi Didier,
thanks for the feedback, it helps, I am still working on this idea and
the syntax. It is a very important product decision, and I am taking
my time, letting it evolve slowly (so I do it right :).
>> So IMO the FK is very often a subset of the PK. I think your first proposal is more generic and should cover also this use case ...
Right I am looking to implement flexible, yet sane controls.
>> My opinion is ordering by PK is enough
This is a strange point, the "ORDER BY (PK)" is technically not
needed, because a foreign key (in AlchemyDB) stores sorted PKs, so the
ordering is implicit, and this directive is more-or-less to make the
command more sensible. I do have to think about if opening this up
will add complexity (seems like it would), I dont want to support
people doing:
"ALTER TABLE ADD CONSTRAINT LIMITROWS 100 KEY (FK) ORDER BY(FK2) "
because this would require an at-trigger-time sort, which is not
performant .... so possibly just documenting that the order is
naturally by PK is the right solution, I dont see any reason for
another type of ordering in these CAP constraints (or none worth
implementing) and every other ordering is not in the Indexes natural
ordering, so it is a bad idea ... so that part of the command is
gone :)
>> primary key was something like id,pos with pos being an integer modulo n
This is basically an implementation of these CAPs in application
logic, so this feature would provide a simple way to do this server-
side. And good to hear that people hit this use-case. The thinking on
these CAP features is that the danger of an InRAMDB is over time, data
that never gets accessed will take up the same resources (RAM) that
really hot data will, and this is just an unacceptable usage of RAM.
>> Your second proposal (constraint expire) looks difficult to implement efficiently because it will probably involve two indexes (one for timestamp,
one for num_views).
It will be difficult to implement, but it will not have multiple-index
or join-like complexity, but not making it have those will be the hard
thing. Capping to both expiration-date AND minval(col) is an extreme
use-case, I put it in just to push this topic to an extreme.
Nevertheless, this can be done by putting a single index on multiple
columns. In the example:
ALTER TABLE ADD CONSTRAINT EXPIRE(timestamp,86400) AND
MINVAL(num_views,100)
The index would be on (timestamp, num_views), so the first part of the
index-lookup would find all rows older than 86400 seconds, and the
second part of the index-lookup would search w/in THOSE rows to find
rows w/ "num_Views less than 100". The AND in the statement means it
can be done w/ a single index that indexes multiple columns. (I did a
poor job explaining this, but if you know multiple column indexes, you
will get it)
Still this is tough/painful to implement and can definitely wait :)
>> daily batch to delete expired rows
I think I will have to have trigger caps, and also cron caps ... this
seems inescapable.
>>triggers and constraints do overlap
this is very true. I initially implemented the LIMITROWS(100) CAP in
Lua here:
https://gist.github.com/780217
the problem is for CAPs like this, running from LUA takes a minimum 2X
more time, and in this case 3X more.
Single threaded servers need to process all OPs AQAP because each OP
blocks ALL others, so this seemed like a use-case that should be
optimised for performance and also standardised, because most people
are gonna be suspicious of triggers calling LUA functions :)
Still this was another example where having LUA as awesome, because I
implemented this stuff in 2 hours, and then decided it needed to be
quicker, so it will be redone in C w/ a simple syntax.
Just FYI (for further discussion and to have it documented in group)
This is how Oracle TimesTen declares their CAPs
1.) LRU Aging run when table reaches maxMB, every reap_interval secs,
stop when table below minMB
ttAgingLRUConfig(minMB,maxMB,reap_interval)
2.) ADD AGING USE ColumnName LIFETIME 86400
So this topic still needs to be thought on .... implementation will
not start for minimum 2-3 weeks.
- Jak