Repository navigation
MDEV-41606 Support line comments in optimizer hints #5935
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
Open
chaitanya-bhardwaj
wants to merge
1
commit into
MariaDB:main
Choose a base branch
from
chaitanya-bhardwaj:mdev-41606-hint-comments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| # MDEV-41606 Comments in new-style optimizer hints | ||
| CREATE TABLE t1 (a INT, KEY(a)); | ||
| CREATE TABLE t2 (a INT, b INT); | ||
| INSERT INTO t1 VALUES (1),(2),(3); | ||
| INSERT INTO t2 VALUES (1,10),(2,20),(3,30); | ||
| # Comments before, between and after hints; commented hints are ignored | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ | ||
| -- NO_INDEX(t1) | ||
| QB_NAME(qb)-- name the query block | ||
| -- INDEX(t1 a) | ||
| NO_INDEX(t1) -- do not use the index | ||
| */ a FROM t1 WHERE a= 2; | ||
| id select_type table type possible_keys key key_len ref rows filtered Extra | ||
| 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where | ||
| Warnings: | ||
| Note 1003 select /*+ QB_NAME(`qb`) NO_INDEX(`t1`@`qb`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 2 | ||
| # Comments inside hint arguments | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ QB_NAME(-- query block name | ||
| qb) NO_INDEX(-- table name | ||
| t1@qb -- index name | ||
| a) */ a FROM t1 WHERE a= 2; | ||
| id select_type table type possible_keys key key_len ref rows filtered Extra | ||
| 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where | ||
| Warnings: | ||
| Note 1003 select /*+ QB_NAME(`qb`) NO_INDEX(`t1`@`qb` `a`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 2 | ||
| # Query block paths and join order from the report | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ | ||
| QB_NAME(child_select, derived1.derived2) -- name the nested block | ||
| -- JOIN_ORDER(@child_select t1, t2) | ||
| JOIN_ORDER(@child_select t2, t1) -- reverse the join order | ||
| */ * FROM | ||
| (SELECT * FROM | ||
| (SELECT t1.a, t2.b FROM t1, t2 WHERE t1.a= t2.a LIMIT 10) | ||
| AS derived2) | ||
| AS derived1; | ||
| id select_type table type possible_keys key key_len ref rows filtered Extra | ||
| 1 PRIMARY <derived3> ALL NULL NULL NULL NULL 3 100.00 | ||
| 3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using where | ||
| 3 DERIVED t1 ref a a 5 test.t2.a 1 100.00 Using index | ||
| Warnings: | ||
| Note 1003 /* select#1 */ select /*+ JOIN_ORDER(@`child_select` `t2`,`t1`) */ `derived2`.`a` AS `a`,`derived2`.`b` AS `b` from (/* select#3 */ select /*+ QB_NAME(`child_select`) */ `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a` limit 10) `derived2` | ||
| # Comments before commas and dots in a query block path | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ | ||
| QB_NAME(child_select -- this is a comment | ||
| ,derived1 -- before the path separator | ||
| . -- after the path separator | ||
| derived2 -- before the closing parenthesis | ||
| ) | ||
| JOIN_ORDER(@child_select t2 -- before a table separator | ||
| , -- after a table separator | ||
| t1) | ||
| */ * FROM | ||
| (SELECT * FROM | ||
| (SELECT t1.a, t2.b FROM t1, t2 WHERE t1.a= t2.a LIMIT 10) | ||
| AS derived2) | ||
| AS derived1; | ||
| id select_type table type possible_keys key key_len ref rows filtered Extra | ||
| 1 PRIMARY <derived3> ALL NULL NULL NULL NULL 3 100.00 | ||
| 3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using where | ||
| 3 DERIVED t1 ref a a 5 test.t2.a 1 100.00 Using index | ||
| Warnings: | ||
| Note 1003 /* select#1 */ select /*+ JOIN_ORDER(@`child_select` `t2`,`t1`) */ `derived2`.`a` AS `a`,`derived2`.`b` AS `b` from (/* select#3 */ select /*+ QB_NAME(`child_select`) */ `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a` limit 10) `derived2` | ||
| # Comments around parentheses and query block qualifiers | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ QB_NAME -- before the opening parenthesis | ||
| ( -- after the opening parenthesis | ||
| qb -- before the closing parenthesis | ||
| ) NO_INDEX -- before the opening parenthesis | ||
| (t1 -- before the query block qualifier | ||
| @ -- after the query block qualifier | ||
| qb a -- before the closing parenthesis | ||
| ) */ a FROM t1 WHERE a= 2; | ||
| id select_type table type possible_keys key key_len ref rows filtered Extra | ||
| 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where | ||
| Warnings: | ||
| Note 1003 select /*+ QB_NAME(`qb`) NO_INDEX(`t1`@`qb` `a`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 2 | ||
| # Comments around numeric arguments | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ MAX_EXECUTION_TIME(-- before the number | ||
| 1000 -- after the number | ||
| ) */ 1; | ||
| id select_type table type possible_keys key key_len ref rows filtered Extra | ||
| 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used | ||
| Warnings: | ||
| Note 1003 select /*+ MAX_EXECUTION_TIME(1000) */ 1 AS `1` | ||
| # A quoted identifier can contain a comment marker | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ QB_NAME(`-- qb`) NO_INDEX(t1@`-- qb`) */ a | ||
| FROM t1 WHERE a= 2; | ||
| id select_type table type possible_keys key key_len ref rows filtered Extra | ||
| 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where | ||
| Warnings: | ||
| Note 1003 select /*+ QB_NAME(`-- qb`) NO_INDEX(`t1`@`-- qb`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 2 | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ QB_NAME("-- qb") NO_INDEX(t1@"-- qb") */ a | ||
| FROM t1 WHERE a= 2; | ||
| id select_type table type possible_keys key key_len ref rows filtered Extra | ||
| 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where | ||
| Warnings: | ||
| Note 1003 select /*+ QB_NAME(`-- qb`) NO_INDEX(`t1`@`-- qb`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 2 | ||
| # A line comment can run up to the end of the hint | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ NO_INDEX(t1) -- INDEX(t1 a) */ a FROM t1 WHERE a= 2; | ||
| id select_type table type possible_keys key key_len ref rows filtered Extra | ||
| 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where | ||
| Warnings: | ||
| Note 1003 select /*+ NO_INDEX(`t1`@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 2 | ||
| # Empty and comment-only hints warn; a bare marker is invalid | ||
| SELECT /*+ */ 1; | ||
| 1 | ||
| 1 | ||
| Warnings: | ||
| Warning 1064 Optimizer hint syntax error near '*/ 1' at line 1 | ||
| SELECT /*+ -- QB_NAME(ignored) */ 1; | ||
| 1 | ||
| 1 | ||
| Warnings: | ||
| Warning 1064 Optimizer hint syntax error near '*/ 1' at line 1 | ||
| SELECT /*+ --*/ 1; | ||
| 1 | ||
| 1 | ||
| Warnings: | ||
| Warning 1064 Optimizer hint syntax error near '--*/ 1' at line 1 | ||
| # Tab and control-byte comment prefixes with CRLF line endings | ||
| SET @stmt= CONCAT('EXPLAIN EXTENDED SELECT /*+ --', CHAR(9), 'ignored', | ||
| CHAR(13), CHAR(10), | ||
| '--', CHAR(1), 'ignored too', CHAR(13), CHAR(10), | ||
| 'NO_INDEX(t1) */ a FROM t1 WHERE a= 2'); | ||
| PREPARE stmt FROM @stmt; | ||
| EXECUTE stmt; | ||
| id select_type table type possible_keys key key_len ref rows filtered Extra | ||
| 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where | ||
| Warnings: | ||
| Note 1003 select /*+ NO_INDEX(`t1`@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 2 | ||
| DEALLOCATE PREPARE stmt; | ||
| # Invalid comment prefixes | ||
| SELECT /*+ --not_a_comment */ 1; | ||
| 1 | ||
| 1 | ||
| Warnings: | ||
| Warning 1064 Optimizer hint syntax error near '--not_a_comment */ 1' at line 1 | ||
| SELECT /*+ - */ 1; | ||
| 1 | ||
| 1 | ||
| Warnings: | ||
| Warning 1064 Optimizer hint syntax error near '- */ 1' at line 1 | ||
| SELECT /*+ QB_NAME(qb)-x ignored */ 1; | ||
| 1 | ||
| 1 | ||
| Warnings: | ||
| Warning 1064 Optimizer hint syntax error near '-x ignored */ 1' at line 1 | ||
| SELECT /*+ QB_NAME(qb)--*/ 1; | ||
| 1 | ||
| 1 | ||
| Warnings: | ||
| Warning 1064 Optimizer hint syntax error near '--*/ 1' at line 1 | ||
| # Other comment forms and split tokens remain invalid | ||
| SELECT /*+ # not a line comment */ 1; | ||
| 1 | ||
| 1 | ||
| Warnings: | ||
| Warning 1064 Optimizer hint syntax error near '# not a line comment */ 1' at line 1 | ||
| SELECT /*+ QB_-- a comment cannot split a keyword | ||
| NAME(qb) */ 1; | ||
| 1 | ||
| 1 | ||
| Warnings: | ||
| Warning 1064 Optimizer hint syntax error near 'QB_-- a comment cannot split a keyword | ||
| NAME(qb) */ 1' at line 1 | ||
| # Syntax errors after a comment retain their line number | ||
| SELECT /*+ | ||
| -- ignored text | ||
| NOT_A_HINT() | ||
| */ 1; | ||
| 1 | ||
| 1 | ||
| Warnings: | ||
| Warning 1064 Optimizer hint syntax error near 'NOT_A_HINT() | ||
| */ 1' at line 3 | ||
| DROP TABLE t1, t2; | ||
| # End of 13.3 tests |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| --echo # MDEV-41606 Comments in new-style optimizer hints | ||
| --enable_prepare_warnings | ||
|
|
||
| CREATE TABLE t1 (a INT, KEY(a)); | ||
| CREATE TABLE t2 (a INT, b INT); | ||
| INSERT INTO t1 VALUES (1),(2),(3); | ||
| INSERT INTO t2 VALUES (1,10),(2,20),(3,30); | ||
|
|
||
| --echo # Comments before, between and after hints; commented hints are ignored | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ | ||
| -- NO_INDEX(t1) | ||
| QB_NAME(qb)-- name the query block | ||
| -- INDEX(t1 a) | ||
| NO_INDEX(t1) -- do not use the index | ||
| */ a FROM t1 WHERE a= 2; | ||
|
|
||
| --echo # Comments inside hint arguments | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ QB_NAME(-- query block name | ||
| qb) NO_INDEX(-- table name | ||
| t1@qb -- index name | ||
| a) */ a FROM t1 WHERE a= 2; | ||
|
|
||
| --echo # Query block paths and join order from the report | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ | ||
| QB_NAME(child_select, derived1.derived2) -- name the nested block | ||
| -- JOIN_ORDER(@child_select t1, t2) | ||
| JOIN_ORDER(@child_select t2, t1) -- reverse the join order | ||
| */ * FROM | ||
| (SELECT * FROM | ||
| (SELECT t1.a, t2.b FROM t1, t2 WHERE t1.a= t2.a LIMIT 10) | ||
| AS derived2) | ||
| AS derived1; | ||
|
|
||
| --echo # Comments before commas and dots in a query block path | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ | ||
| QB_NAME(child_select -- this is a comment | ||
| ,derived1 -- before the path separator | ||
| . -- after the path separator | ||
| derived2 -- before the closing parenthesis | ||
| ) | ||
| JOIN_ORDER(@child_select t2 -- before a table separator | ||
| , -- after a table separator | ||
| t1) | ||
| */ * FROM | ||
| (SELECT * FROM | ||
| (SELECT t1.a, t2.b FROM t1, t2 WHERE t1.a= t2.a LIMIT 10) | ||
| AS derived2) | ||
| AS derived1; | ||
|
|
||
| --echo # Comments around parentheses and query block qualifiers | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ QB_NAME -- before the opening parenthesis | ||
| ( -- after the opening parenthesis | ||
| qb -- before the closing parenthesis | ||
| ) NO_INDEX -- before the opening parenthesis | ||
| (t1 -- before the query block qualifier | ||
| @ -- after the query block qualifier | ||
| qb a -- before the closing parenthesis | ||
| ) */ a FROM t1 WHERE a= 2; | ||
|
|
||
| --echo # Comments around numeric arguments | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ MAX_EXECUTION_TIME(-- before the number | ||
| 1000 -- after the number | ||
| ) */ 1; | ||
|
|
||
| --echo # A quoted identifier can contain a comment marker | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ QB_NAME(`-- qb`) NO_INDEX(t1@`-- qb`) */ a | ||
| FROM t1 WHERE a= 2; | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ QB_NAME("-- qb") NO_INDEX(t1@"-- qb") */ a | ||
| FROM t1 WHERE a= 2; | ||
|
|
||
| --echo # A line comment can run up to the end of the hint | ||
| EXPLAIN EXTENDED | ||
| SELECT /*+ NO_INDEX(t1) -- INDEX(t1 a) */ a FROM t1 WHERE a= 2; | ||
|
|
||
| --echo # Empty and comment-only hints warn; a bare marker is invalid | ||
| SELECT /*+ */ 1; | ||
| SELECT /*+ -- QB_NAME(ignored) */ 1; | ||
| SELECT /*+ --*/ 1; | ||
|
|
||
| --echo # Tab and control-byte comment prefixes with CRLF line endings | ||
| SET @stmt= CONCAT('EXPLAIN EXTENDED SELECT /*+ --', CHAR(9), 'ignored', | ||
| CHAR(13), CHAR(10), | ||
| '--', CHAR(1), 'ignored too', CHAR(13), CHAR(10), | ||
| 'NO_INDEX(t1) */ a FROM t1 WHERE a= 2'); | ||
| PREPARE stmt FROM @stmt; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| --echo # Invalid comment prefixes | ||
| SELECT /*+ --not_a_comment */ 1; | ||
| SELECT /*+ - */ 1; | ||
| SELECT /*+ QB_NAME(qb)-x ignored */ 1; | ||
| SELECT /*+ QB_NAME(qb)--*/ 1; | ||
|
|
||
| --echo # Other comment forms and split tokens remain invalid | ||
| SELECT /*+ # not a line comment */ 1; | ||
| SELECT /*+ QB_-- a comment cannot split a keyword | ||
| NAME(qb) */ 1; | ||
|
|
||
| --echo # Syntax errors after a comment retain their line number | ||
| SELECT /*+ | ||
| -- ignored text | ||
| NOT_A_HINT() | ||
| */ 1; | ||
|
|
||
| DROP TABLE t1, t2; | ||
|
|
||
| --echo # End of 13.3 tests | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.