by rtpg · 4y ago · 0 comments
Just yesterday i spent time debugging a whole query thing cuz heuristics made the planner plan the wrong thing.
The planner is pretty amazing black magic that can just make life easy (just like compilers do a bunch of cool stuff.
But I think SQL perf would be a lot easier for people to grok if the low level involved specifying “hey, system, go through this btree, pull these items, merge with items from this other btree, etc”
SELECT * FROM js_query('...');
Where the query is a JS snippet that has access to low level access methods, e.g.:
var results = [];
var cursor = myTable.indexes.foo.seek('item-23');
while (cursor.next()) {
results.push(cursor.row());
}
return results;
However, it turns out this would be a lot of work and it's difficult to make it work with features like row level security.Since I didn't have enough time I dropped the idea, but it'd be awesome if somebody hacked this up at some point : ).
What I've always wanted in Postgres in one quote expect to also allow other index types (e.g. Hash/BRIN/etc) in its language.
Side benefit: It also allows dev's to understand the pro's/con's of these constructs when using each one and build up their knowledge on what is really just algo's and data structures.
I guess that there must be a good number of people who would use it in PostgreSQL. Anybody analyzed previous tries to implement it?