-
Notifications
You must be signed in to change notification settings - Fork 116
[SQL] Propagate join hints through compiler stages #6162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
60b229f
4e5c895
994081c
f2d8197
fff9bf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -347,7 +347,7 @@ values | |
| : { VALUES | VALUE } expression [, expression ]* | ||
|
|
||
| select | ||
| : SELECT [ ALL | DISTINCT ] | ||
| : SELECT [ hintComment ] [ ALL | DISTINCT ] | ||
| { projectItem [, projectItem ]* } | ||
| FROM tableExpression | ||
| [ WHERE booleanExpression ] | ||
|
|
@@ -360,7 +360,7 @@ select | |
| ``` | ||
| tablePrimary | ||
| : tableName '(' TABLE tableName ')' | ||
| | tablePrimary '(' columnDecl [, columnDecl ]* ')' | ||
| | tablePrimary [ hintComment ] '(' columnDecl [, columnDecl ]* ')' | ||
| | [ LATERAL ] '(' query ')' | ||
| | UNNEST '(' expression ')' [ WITH ORDINALITY ] | ||
| | TABLE '(' functionName '(' expression [, expression ]* ')' ')' | ||
|
|
@@ -442,6 +442,67 @@ the column names are *not* used to reorder columns. | |
| In `orderItem`, if expression is a positive integer n, it denotes the | ||
| nth item in the `SELECT` clause. | ||
|
|
||
| ## SQL hints | ||
|
|
||
| A hint is an instruction to the optimizer. When writing SQL, you may | ||
| know information about the data unknown to the optimizer. Hints | ||
| enable you to make decisions normally made by the optimizer. | ||
|
|
||
| We support hints in two locations: | ||
|
|
||
| - Query Hint: right after the `SELECT` keyword; | ||
| - Table Hint: right after the referenced table or view name. | ||
|
|
||
| ``` | ||
| SELECT /*+ broadcast(S), shard(T) */ | ||
| FROM | ||
| T /*+ size(5) */ | ||
| JOIN | ||
| S | ||
| ``` | ||
|
|
||
| The syntax of hints is: | ||
|
|
||
| ``` | ||
| hintComment | ||
| : '/*+' hint [, hint ]* '*/' | ||
|
|
||
| hint: | ||
| hintName | ||
| | hintName '(' optionKey '=' optionVal [, optionKey '=' optionVal ]* ')' | ||
| | hintName '(' hintOption [, hintOption ]* ')' | ||
|
|
||
| optionKey | ||
| : simpleIdentifier | ||
| | stringLiteral | ||
|
|
||
| optionVal | ||
| : simpleIdentifier | ||
| | stringLiteral | ||
|
|
||
| hintOption | ||
| : simpleIdentifier | ||
| | numericLiteral | ||
| | stringLiteral | ||
| ``` | ||
|
|
||
| ### Supported hints and their impact on query implementation | ||
|
|
||
| :::warning | ||
|
|
||
| These hints are considered still experimental, and they may change | ||
|
|
||
| ::: | ||
|
|
||
| - `broadcast(`*table*`)`: Indicates that the following `JOIN` should be implemented using | ||
| a broadcast-join strategy by broadcasting the input with alias *table* | ||
| - `shard(`*table*`)`: Indicates that the following `JOIN` should be implemented using | ||
| a hash-join strategy by sharding the input with alias *table* | ||
| - `balance(`*table*`)`: Indicates that the following `JOIN` should be implemented using | ||
| a balanced strategy by hashing on all fields the input with alias *table* | ||
|
|
||
| Note: specifying hints may inhibit some compiler optimizations. | ||
|
|
||
| ## Creating indexes | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section is empty other than "Support for hints is under development." Since the parser now accepts |
||
| Feldera supports the `CREATE INDEX` SQL statement with the following | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc/code mismatch: this lists the hint as
balanced(table), but the registered hint name isbalance—HINT_BALANCE = "balance"inSqlToRelCompiler, and the newtestThreeWayJoinHintswrites/*+ ... balance(U) */. A user copying the docs verbatim with/*+ balanced(U) */will get an unknown hint that silently no-ops. Either rename the constant tobalancedor fix the docs to saybalance(table).