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

Optimise the use case where the two conditions overlap in an = #38

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nterbogt
Copy link

@nterbogt nterbogt commented May 3, 2023

There is a special use case where the depth and the start overlap and create SQL that looks like (a <= x) & (a >= x)... this is equivalent to (a=x) and as a result allows better use of the table indexes, specifically the (id, revision_id, left_pos, right_pos, depth).

Before optimisation:

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE parent const PRIMARY,IDX_E1907B87BF3967501DFA7C8F5E183DDBDEADD74FAA31C69,IDX_E1907B875E183DDBDEADD74,IDX_E1907B87BDEADD74 PRIMARY 8 const,const 1
1 SIMPLE child range IDX_E1907B875E183DDBDEADD74,IDX_E1907B87BDEADD74,IDX_E1907B87FAA31C69 IDX_E1907B87BDEADD74 20 NULL 145780 Using index condition; Using where; Using filesort

After optimisation:

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE parent const PRIMARY,IDX_E1907B87BF3967501DFA7C8F5E183DDBDEADD74FAA31C69,IDX_E1907B875E183DDBDEADD74,IDX_E1907B87BDEADD74 PRIMARY 8 const,const 1
1 SIMPLE child ref,filter IDX_E1907B875E183DDBDEADD74,IDX_E1907B87BDEADD74,IDX_E1907B87FAA31C69 IDX_E1907B87FAA31C69,IDX_E1907B87BDEADD74 4,4 const 12148 Using index condition; Using where; Using filesort; Using rowid filter

@nterbogt nterbogt marked this pull request as draft May 3, 2023 23:51
@nterbogt
Copy link
Author

nterbogt commented May 3, 2023

All tests passed on this, but there might be a slight flaw in the math. Putting in Draft until I can review.

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