Skip to content

Add in clause support for selectDBA statement#8360

Closed
bravehearto0 wants to merge 5 commits intovitessio:mainfrom
BlitzScaling:ss-fix-select-DBA-in-clause
Closed

Add in clause support for selectDBA statement#8360
bravehearto0 wants to merge 5 commits intovitessio:mainfrom
BlitzScaling:ss-fix-select-DBA-in-clause

Conversation

@bravehearto0
Copy link

@bravehearto0 bravehearto0 commented Jun 22, 2021

support correct parsing for the following scenarios for select DBA statement :
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA IN ('commerce');

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA IN ('commerce', 'product');

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE (TABLE_SCHEMA,TABLE_NAME) IN (('commerce', 'product'));

select table_schema, table_name, column_name from information_schema.columns where (table_schema, table_name, lower(column_name)) in (('milkyway_production', 'user_uploaded_media', 'uuid'));

Noticed that due to the vttableschema and vttablename is still limited to 1, the actual query execution of above one may return less than what should be returned. The reason is vtgate using a map to track the overiden schema & table name, which could be only one. Further fix needed to make it work end to end.

Originally the code normalize the query
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA IN ('commerce', 'product');
to
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA IN ::__vtg1;

this is undesired, because we need to rewrite the query to

"Query": "select * from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA in (:__vtschemaname, :__vtschemaname)",
"SysTableTableSchema": "[VARBINARY("commerce"), VARBINARY("product")]"

There are two ways to fix this:

  1. rewrite the logic in normalize.go, make sure parse it like SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA IN (:__vtg1, :__vtg2);
  2. add logic in normalize criteria and skip the normalization if it is a system table.

After implementing both, I found the 2 is less risky and has much less impact than 1.

Signed-off-by: bravehearto0 <shiruisheng88@gmail.com>
Signed-off-by: bravehearto0 <shiruisheng88@gmail.com>
Signed-off-by: bravehearto0 <shiruisheng88@gmail.com>
Signed-off-by: bravehearto0 <shiruisheng88@gmail.com>
Signed-off-by: bravehearto0 <shiruisheng88@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant