Back to work
After this extended Christmas week-end, I decided to restart work with a simple problem. I worked on a mechanism to push variables to queries at runtime and a way to optimise it. You will find an example if you continue reading. A first version is working, but I am adding a few refinements so that the selection optimiser detects some tricky situations where the variables in the comparison are hidden behind let statements.
Here is an example of this: to find every book published by every author in a database, you use the following SLinks program:[bag {auth.#name,
[lst pub.#title | ^pub <lst (table "publication" with {#publication_id:int,#author_id:int,#title:string} order [#title:asc] from db), pub.#author_id == auth.#author_id]
} | ^auth <bag (table "author" with {#author_id:int,#name:string} from db)];
This is how it look after the current optimisation phase and in internal representation (slightly simplified):for auth <bag table 'SELECT table_10.author_id AS author_id, table_10.name AS name FROM author AS table_10' from db in
[bag {
#1=let {auth.#name,
#2=(for pub <bag table '(SELECT table_5.author_id AS author_id, table_5.title AS title FROM publication AS table_5)' from db in
(if (pub.#author_id == auth.#author_id) then [bag pub.#title] else [bag])
}];
However, the (pub.#author_id == auth.#author_id) comparison could be pushed into the second SQL query since auth.#author_id is known when the query is executed. This would lead to a new optimised expressions like this:...
#2=(for pub <bag table '(SELECT table_5.author_id AS author_id, table_5.title AS title FROM publication AS table_5 WHERE table_5.author_id = $ table.#author_id $)' from db in
[bag pub.#title]
...
Where the expression between $s in the SQL query is added to it at runtime.