Projection optimisation
I had promised yesterday not to post anything until I have something interesting to report. But since it would be sad to break the uninterrupted row of entries I have been producing for two month, and since I have something to report, here it is:
Projections are now optimised into SQL queries. That means that the system will only query the database for the columns it will actually really need. Read on for an example. Before that, I also added another optimisation to try out the optimisation mechanism: remove 'let' operators that declare variables that won't be used. But this will probably disappear from the final version since it is not an acceptable optimisation if there are side-effects, and for an interpreter, might even be counter-productive.
I have also improved the syntactic sugar module because it was producing useless 'let', that were simply renaming variables, when handling pattern matching.
Here is an example of projection optimisation (in SLinks' verbose debug mode):? [set x.#a | ^x <bag (table "tata" with [bag {#a:pre(int),#b:pre(string),#c:pre(float)}] from db)];;
Raw: (for x <bag table '(SELECT tata.a AS a, tata.b AS b, tata.c AS c FROM tata WHERE true)' from db in [set (let {#a=$gv3$|$gv4$} = x in $gv3$)])
Opt: (for x <bag table '(SELECT tata.a AS a FROM tata WHERE true)' from db in [set (let {#a=$gv3$|$gv4$} = x in $gv3$)])
Is: [set 1, 2, 3] : [set int]
'Raw' is a string representation of the AST for the expression. One can see the effect of syntactic sugar: comprehensions are transformed into simpler 'for' expressions and the dot notation becomes a record selection operation. 'Opt' is the AST after it has been optimised. Notice that the query now only fetches the 'a' column that will be needed later.