Repository navigation
Description
Several bugs come from how expressions find what they refer to. Expression nodes compare and name themselves by their toString() text and list their children by hand in each function that walks them, and a column is matched to its table while the JavaScript is generated, partly by guessing. Each statement also looks up the database of db.table on its own.
What this issue is about
This issue asks for a change in structure, not for a fix of each bug listed below. The bugs show where the current structure fails, and they serve as test cases. Most of them go away as a result of the two changes, and the rest are fixed in the new structure.
-
Node classes with declared children and one walker. Each expression class (
Op,UniOp,Column,FuncValue,AggrValueand the others) lists its child slots once, for examplestatic children = ['left', 'right', 'right1', 'right2', 'escape']onOp. Walking the tree, comparing two expressions, hashing and printing are then written once on a shared base class, not by hand in each class and in each function that walks the tree, such asfindAggregator. Two expressions are equal when their structure is equal, not when their text is. -
A bind step between parsing and code generation.
bind(statement, db)runs once after parsing. It builds one scope per SELECT with its sources and a link to the outer SELECT, and records on eachColumnwhich source and which column it refers to. It also resolves eachdb.tableonce. Code generation then only reads whatbindrecorded, soColumn.toJSwritesp[source][column]without guessing, and statements no longer look up their database themselves.
Ground rules
- Results stay as in 4.x. Where a rule is a choice (an ambiguous column name, an alias against a column of the same name),
bindapplies today's rule. Only the bugs a pull request names may change results. - Small steps. A good first pull request adds
static childrenand a genericwalk()andequals(), and uses them infindAggregatorand in the de-duplication of aggregates (todayagg.toString() === this.toString()). That fixes SELECT (a+1) ... GROUP BY a+1 drops the column #2721. The text changes of Keep ESCAPE in the text of a LIKE expression #2674 and Keep the elements of ARRAY[...] in its text #2691 are not part of it. The text of an expression is also its column name, so Restore 4.20.1 behaviour for multi-character ESCAPE and the names of LIKE ... ESCAPE and ARRAY[...] columns #2750 restored the 4.20.1 names, and they stay as they are in 4.x. The next one addsbind, at first only to resolvedb.table(Review #2201 for code improvements: each statement resolves db.table on its own #2705). - Each pull request passes the full test suite and the parity check in
test/parity/against the build before it. - The node types become ES6 classes as part of this work, not in a separate pass.
Bugs traced to this
- Text used as identity: Keep ESCAPE in the text of a LIKE expression #2674, Keep the elements of ARRAY[...] in its text #2691 (both reverted by Restore 4.20.1 behaviour for multi-character ESCAPE and the names of LIKE ... ESCAPE and ARRAY[...] columns #2750 to keep the 4.20.1 column names), SELECT (a+1) ... GROUP BY a+1 drops the column #2721
- A walker that missed a node's parts: [WIP] Fix BETWEEN operator issue in CASE statement #2195
- Column lookup by guessing: Built-in functions read an unqualified column from the first table in a JOIN #2615, Review #2297 for code improvements: grouped columns looked up by bare name #2640, Correlated subquery with an unqualified outer column returns no rows #2644, Write the per-row read of a column from a source without column definitions only in the binding #2680
db.tableresolved per statement: Use the table's own database in ALTER TABLE RENAME TO and SHOW CREATE TABLE #2704, Review #2201 for code improvements: each statement resolves db.table on its own #2705- Alias against column decided in several places: Let HAVING use a SELECT alias to close #887 #2672, Review #2398 for code improvements: GROUP BY prefers a SELECT alias over a table column #2709
Activity
Work out the binding only when Column.onBind is set and run the bindi…
Refactor: Correct the header comment of bind.js (#2723)
Refactor: Keep the text of the error for a database that does not exi…
Refactor: Keep the variable that the error of a missing database names (