Commit 2f11d20
authored
feat: Initial support for grouped join pushdown (#9032)
* Load request extended with list of grouped subqueries to join with. Each subquery come with SQL string, alias, condition and join type. SQL is treated as static query, fully porcessed by SQL API. Condition - as member expression, because it can contain references to dimensions
* `BaseQuery` will add grouped subqueries to SQL after subquery dimensions and join tree parts
* Wrapper rewrite rules handle `wrapper_pullup_replacer` in `join` position of `wrapped_select`, but still mostly with empty list inside. Notable exception is aggregation flattening - it is allowed to try to flatten aggregation into WrappedSelect with non-empty joins.
* Wrapper pull up rules no handle trivial pulling up over single `wrapped_select_join` and over list `WrappedSelectJoins` list
* Wrapper replacers now have `grouped_subqueries` in a context, it is used to track qualifiers of grouped subqueries, to allow rewriting of column expressions referencing grouped subquery with push-to-cube active
* Converter from egraph to logical plan reconstructs schema for joins
* Penalize joins harder than wrappers. For queries ungrouped queries with grouped join, like `SELECT * FROM (ungrouped) JOIN (grouped);`, this would allow to prefer representation without join, but with wrapper. Without this cost change join representation would have higher `ast_size_outside_wrapper` component, but it is less important then `wrapper_nodes`, so wrapper representation would be more expensive.
* SQL generation for `WrappedSelectNode` will generate each grouped subquery separately, generate member expressions for join conditions and push all that to Cube
* Rewrite rules are too relaxed for now: they allow any `push_to_cube=false` query as grouped, which is incorrect, as we may drop push-to-Cube when wrapping `WrappedSelect` with another layer, even if inner `WrappedSelect` is projection. This is covered by check in SQL generation: only `CubeScan(grouped=true)` are allowed. This require new flag in wrapper replacers to fix.
Supporting changes:
* Extract `CubeScanWrappedSqlNode` from `CubeScanWrapperNode`. Both a logical plan nodes for now, `Wrapper` is generated during rewrites, and `WrappedSql` stores SQL, generated generated during `evaluate_wrapped_sql`
* Extracted `__cubeJoinField` join check to function, and make it stricter, only `left.__cubeJoinField = right.__cubeJoinField` is allowed
* Avoid clone calls in `find_column_by_alias` and `__cubeJoinField` join check
* Add `PushToCubeContext` in SQL generation code, used to track everything necessary to generate SQL for push-to-Cube case. For now it contains ungrouped `CubeScanNode` that whould be pushed into, and qualifiers and generated SQL for all grouped subqueries. Qualifiers are necessary to generate column expressions on top of ungrouped-grouped join.
* New `copy_value!` macro, to extend `copy_flag!`, allows to copy single value between different unary language variants
* Prettify extracted best plan and cost in logs1 parent aaa4364 commit 2f11d20
File tree
56 files changed
+2784
-718
lines changed- packages
- cubejs-api-gateway
- src
- types
- cubejs-schema-compiler/src/adapter
- cubejs-testing/test
- __snapshots__
- rust/cubesql
- cubeclient
- .openapi-generator
- src/models
- cubesql/src
- compile
- engine/df
- rewrite
- rules
- wrapper
- test
- transport
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
56 files changed
+2784
-718
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
332 | 350 | | |
333 | 351 | | |
334 | 352 | | |
| |||
366 | 384 | | |
367 | 385 | | |
368 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
369 | 393 | | |
370 | 394 | | |
371 | 395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1312 | 1312 | | |
1313 | 1313 | | |
1314 | 1314 | | |
1315 | | - | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
1316 | 1321 | | |
1317 | 1322 | | |
1318 | 1323 | | |
| |||
1323 | 1328 | | |
1324 | 1329 | | |
1325 | 1330 | | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
1326 | 1335 | | |
1327 | 1336 | | |
1328 | 1337 | | |
| |||
1361 | 1370 | | |
1362 | 1371 | | |
1363 | 1372 | | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
1364 | 1377 | | |
1365 | 1378 | | |
1366 | 1379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
99 | 108 | | |
100 | 109 | | |
101 | 110 | | |
| |||
122 | 131 | | |
123 | 132 | | |
124 | 133 | | |
| 134 | + | |
125 | 135 | | |
126 | 136 | | |
127 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
70 | 79 | | |
71 | 80 | | |
72 | 81 | | |
| |||
85 | 94 | | |
86 | 95 | | |
87 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
88 | 100 | | |
89 | 101 | | |
90 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
63 | 80 | | |
64 | 81 | | |
65 | 82 | | |
| |||
224 | 241 | | |
225 | 242 | | |
226 | 243 | | |
| 244 | + | |
227 | 245 | | |
228 | 246 | | |
229 | 247 | | |
| |||
269 | 287 | | |
270 | 288 | | |
271 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
272 | 295 | | |
273 | 296 | | |
274 | 297 | | |
| |||
1604 | 1627 | | |
1605 | 1628 | | |
1606 | 1629 | | |
1607 | | - | |
| 1630 | + | |
| 1631 | + | |
1608 | 1632 | | |
1609 | 1633 | | |
1610 | 1634 | | |
1611 | 1635 | | |
1612 | 1636 | | |
1613 | 1637 | | |
1614 | | - | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
1615 | 1642 | | |
1616 | 1643 | | |
1617 | 1644 | | |
1618 | 1645 | | |
1619 | 1646 | | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
1620 | 1668 | | |
1621 | 1669 | | |
1622 | 1670 | | |
| |||
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
60 | 86 | | |
61 | 87 | | |
62 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
479 | 538 | | |
480 | 539 | | |
481 | 540 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
0 commit comments