Skip to content
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

SQL subqueries result in fully fragmented lookups and Cartesian products #21114

Open
lwk595ww opened this issue Sep 21, 2022 · 2 comments
Open

Comments

@lwk595ww
Copy link

Condition: I am using compound sharding and I am using a custom sharding strategy.

The SQL statement: select t10.* from user t10 where t10.id in (select t11.user_id from school t11 where t11.id = 1571685907277340673 and t11.tenantId = 'caba6901') and t10.tenantId = 'caba6901'

Test conclusion: This SQL removes the custom policy, but returns two result sets in the source code. One is the table name returned by the custom sharding policy, and one is the table name returned by the full sharding, which results in a Cartesian product between the primary table and the child table

image

image

image

image

image

The above figure shows that under the same logical table, the conditions of two logical tables are cycled, causing the logical table cannot match the logical table name of the conditions, and the framework returns full sharding

The last figure shows that after the SQL is decomposed by the framework, each decomposed SQL matches all the sharding conditions, resulting in each logical table returning two sets of real tables, which, when merged, becomes a full sharding lookup.

image

Can you determine whether different conditions belong to different logical tables at this point in the source code, to avoid conditions that do not belong to this logical table also walk the logic, resulting in full fragmentation

@lwk595ww
Copy link
Author

image

Modify the source code, the sub-query mixture condition isolation, respectively routing can solve the problem of nested sub-query both inside and outside layers have fragmentation and full routing, I hope the official can have a look, test, I hope the official can release a version

@github-actions
Copy link

github-actions bot commented Oct 8, 2022

Hello , this issue has not received a reply for several days.
This issue is supposed to be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants