-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
32982: parser: scan and split statements before parsing, return SQL strings for statements r=RaduBerinde a=RaduBerinde These series of changes move the handling of `;` out of the parser and into a pre-processing stage (which scans lexical tokens and splits statements). The Parser now returns the strings for the statements, which are then used instead of `String()`. Eventually we will cache ASTs and these strings will be used to look up ASTs in the cache and avoid parsing entirely. Functionally, only two small things change (both positive IMO): - traces and logs now show the original SQL instead of the roundtripped string - when we hit a parsing error in a multi-statement, we now show only the relevant statement (this is what postgres shows too). In principle, this should be less efficient because we need to remember the scanned tokens. However, I made some improvements that offset the overhead. Also note that the code that handled multiple statements in sql.y was inefficient (every prefix of the `[]tree.Statement` slice was being copied on heap when we assigned it to the `val interface{}`). #### parser: split lexer This change splits the lexer into two parts: - `scanner` does the low-level scanning of the tokens - `lexer` operates on a slice of tokens, performs lookahead and handles errors The separation of these steps will allow us to split statements and parse each one individually. Release note: None #### parser: split statements prior to parsing This change uses the scanner to split the input into statements and then parses each one independently. This will allow the caller to get the exact SQL for each statement. The SQL grammar does not allow for semicolons anymore. Release note: None #### parser: make sqlSymType smaller Change `id` and `pos` to `int32` to make the structure smaller. Release note: None #### parser: return SQL strings alongside the statements Release note: None Benchmarks: ``` name old time/op new time/op delta Parse/simple 11.8µs ± 5% 9.5µs ± 1% -19.22% (p=0.000 n=12+12) Parse/string 15.8µs ± 3% 13.6µs ± 1% -13.95% (p=0.000 n=12+12) Parse/tpcc-delivery 19.8µs ± 3% 19.0µs ± 2% -4.18% (p=0.000 n=12+12) Parse/account 34.0µs ± 2% 33.8µs ± 4% ~ (p=0.101 n=12+12) name old alloc/op new alloc/op delta Parse/simple 2.44kB ± 0% 2.52kB ± 0% +3.28% (p=0.000 n=12+12) Parse/string 2.71kB ± 0% 3.56kB ± 0% +31.33% (p=0.000 n=12+12) Parse/tpcc-delivery 3.10kB ± 0% 5.49kB ± 0% +76.80% (p=0.000 n=12+12) Parse/account 5.81kB ± 0% 9.06kB ± 0% +55.92% (p=0.000 n=12+12) name old allocs/op new allocs/op delta Parse/simple 23.0 ± 0% 21.0 ± 0% -8.70% (p=0.000 n=12+12) Parse/string 27.0 ± 0% 26.0 ± 0% -3.70% (p=0.000 n=12+12) Parse/tpcc-delivery 35.0 ± 0% 35.0 ± 0% ~ (all equal) Parse/account 81.0 ± 0% 81.0 ± 0% ~ (all equal) ``` Co-authored-by: Radu Berinde <[email protected]>
- Loading branch information
Showing
32 changed files
with
702 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
stmt_block ::= | ||
stmt_list | ||
|
||
stmt_list ::= | ||
( stmt ) ( ( ';' stmt ) )* | ||
stmt | ||
|
||
stmt ::= | ||
'HELPTOKEN' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.