Handle Multiple ORDER BYs with DEFAULTs - #127
Conversation
Greptile SummaryThis PR implements support for multiple
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| centrallix-doc/SQL.txt | Adds documentation for multi-ORDER BY and DEFAULT keyword; one sentence in the new paragraph inaccurately implies only the last ORDER BY clause is ever appended. |
| centrallix/multiquery/multiquery.c | Adds ORDER BY merge logic in PostProcess and DEFAULT keyword parsing in SyntaxParse. Memory management is handled correctly (children are moved before FreeQS), pointer-based last_orderby tracking is stable through removals, and the ob parameter is safely re-derived from scratch. |
| centrallix/include/multiquery.h | Adds MQ_SF_DEFAULTORDER flag (65536) with no conflicts in the existing bitmask sequence. |
| centrallix/tests/test_sql_orderby_05.to | Seven test cases covering single ORDER BY, multi ORDER BY merge, DEFAULT override, lone DEFAULT, double-DEFAULT, and mixed three-clause scenarios. |
| centrallix/tests/test_sql_orderby_05.cmp | Expected output for all seven test cases; results are consistent with the described DEFAULT-overwrite semantics. |
| centrallix-sysdoc/BeeleyCodingStyle.md | Minor prose clarification in the comment-style rule; no functional impact. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Parse SQL tokens] --> B{ORDER BY token?}
B -- No --> C[Other clause handling]
B -- Yes --> D[Allocate MQ_T_ORDERBYCLAUSE node]
D --> E{Next token == DEFAULT?}
E -- Yes --> F[Set MQ_SF_DEFAULTORDER flag]
E -- No --> G[mlxHoldToken - push back]
F --> H[Parse ORDER BY items]
G --> H
H --> I[Add clause to qs->Children]
I --> J[Continue parsing...]
J --> K[mq_internal_PostProcess]
K --> L[Pass 1: find last ORDER BY node]
L --> M[Reset ob = NULL, iterate children]
M --> N{NodeType == ORDERBYCLAUSE?}
N -- No --> O[Skip, i++]
N -- Yes --> P{DEFAULT flag AND not last?}
P -- Yes --> Q[xaRemoveItem + FreeQS, cnt--]
P -- No --> R{ob == NULL?}
R -- Yes --> S[ob = subtree, i++]
R -- No --> T[Move children to ob, xaClear, FreeQS, cnt--]
S --> U[Compile ORDER BY expressions]
T --> U
Q --> M
Reviews (2): Last reviewed commit: "Update default to be a reserved word." | Re-trigger Greptile
|
This PR is ready for human review. |
gbeeley
left a comment
There was a problem hiding this comment.
A couple of changes needed - thanks!
|
|
||
| /** Drop a DEFAULT clause that isn't the last one. **/ | ||
| if ((subtree->Flags & MQ_SF_DEFAULTORDER) && !is_last) | ||
| goto remove_order_by_element; |
There was a problem hiding this comment.
Avoid the goto since this isn't a retry mechanism or an error condition handler, and since this can be easily refactored as an if() block.
There was a problem hiding this comment.
goto removed.
|
@gbeeley I think I've resolved your comments. |
|
Let's resolve PR 117 first, moving to XArray, and then revisit this one. |
|
This PR no longer seems to be of trivial size. |
The move to XArray for OrderBy in PR #117 has been completed. |
This PR will add functionality for handling multiple
ORDER BYstatements. Later statements append to earlier ones, or overwrite them if they use theDEFAULTkeyword, as suggested by Greg.This PR includes both docs and testing for the new functionality and the
DEFAULTkeyword.