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

fix: consent cockroachdb perfomance issue with zigzag join query #1790

Merged
merged 1 commit into from
May 22, 2020

Conversation

lopezator
Copy link
Contributor

Add an index over subject and client_id in order to avoid the
(sometimes) underperformant zigzag join query.

Closes #1789
Related to #1755 cockroachdb/cockroach#47179

After applying the proposed index, the query plan now avoids the zigzag join query, reducing the query times from 50s to 2s in worst cases in my tests.

	distributed	true
	vectorized	false
sort		
 │	order	-requested_at
 └── render		
      └── lookup-join		
           │	table	hydra_oauth2_consent_request_handled@primary
           │	type	inner
           │	equality	(challenge) = (challenge)
           │	equality cols are key	
           │	parallel	
           │	pred	"(@9 = '{}') AND (@7 = true)"
           └── filter		
                │	filter	skip = false
                └── index-join		
                     │	table	hydra_oauth2_consent_request@primary
                     └── scan		
	table	hydra_oauth2_consent_request@hydra_oauth2_consent_request_client_id_subject_idx
	spans	"/""myclient""/""my@subject.com""-/""my-client""/""my@subject.com""/PrefixEnd"

@CLAassistant
Copy link

CLAassistant commented Apr 8, 2020

CLA assistant check
All committers have signed the CLA.

@lopezator lopezator changed the title consent: fix cockroachdb perfomance issue with zigzag join query fix: consent cockroachdb perfomance issue with zigzag join query Apr 8, 2020
@aeneasr
Copy link
Member

aeneasr commented Apr 10, 2020

Thank you! The migrations still need to be improved but since @zepatrik is refactoring that at the moment I think it makes sense to include this in his PR / after his merge!

@aeneasr aeneasr added this to In progress in Maintainer's Board via automation Apr 10, 2020
@zepatrik
Copy link
Member

Hey @lopezator
The migration PR is finally done, can you adopt this PR to the new migration format? Basically you just have to split the migration in two *.cockroach.up.sql and *.cockroach.down.sql files.
Please also add empty migrations for the other databases, I'm pretty sure the migrator will be confused when the numbers don't match (files without the database name in it will be applied to all databases without specific files)

@lopezator
Copy link
Contributor Author

@zepatrik What would be exactly the file naming convention? Something related to date? I see that every migration file starts by 2019

@zepatrik
Copy link
Member

zepatrik commented May 6, 2020

You can either use gobuffalo's soda cli to generate the files or just copy an existing one and increase the number. It is usually of the format YYYYMMDDHHMMSS_name(.database)?.(up|down).(sql|fizz)

@lopezator
Copy link
Contributor Author

Ok!

Do you prefer empty migrations for postgres and mysql or are you ok on adding the index for all the databases?

I think that this index might not add as much value as it adds for cockroachdb, but as long as there are queries on that table using both fields in the where clause this could be beneficial for them also.

Let me know what you think.

@zepatrik
Copy link
Member

zepatrik commented May 6, 2020

Think you can apply it to all or @aeneasr ?

@aeneasr
Copy link
Member

aeneasr commented May 6, 2020

apply for all should be ok!

@lopezator lopezator force-pushed the fix/zigzag-join branch 2 times, most recently from 4e6307f to a6d2106 Compare May 7, 2020 06:51
@lopezator
Copy link
Contributor Author

apply for all should be ok!

Cool!

PTAL @zepatrik

@zepatrik
Copy link
Member

zepatrik commented May 9, 2020

right let me fix that I know what the problem is

@zepatrik
Copy link
Member

zepatrik commented May 9, 2020

It's actually not a problem with the test.
@lopezator you have to apply your migration after all others, just put the current date/time there.
Or use soda generate sql consent-request-index.
If the migration for all databases is the same you should be able to omit the database name in the file completely and just have one up and one down.

@zepatrik
Copy link
Member

zepatrik commented May 9, 2020

The question remains: why did the mysql test pass??

Add an index over subject and client_id in order to avoid the
(sometimes) underperformant zigzag join query.

Closes ory#1789
Related to ory#1755 cockroachdb/cockroach#47179
@lopezator
Copy link
Contributor Author

The question remains: why did the mysql test pass??

Good question 😅

PTAL @zepatrik

Maintainer's Board automation moved this from In progress to Reviewer approved May 22, 2020
Copy link
Member

@zepatrik zepatrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @aeneasr

@aeneasr
Copy link
Member

aeneasr commented May 22, 2020

Thank you both for the great work!

@aeneasr aeneasr merged commit 615387e into ory:master May 22, 2020
Maintainer's Board automation moved this from Reviewer approved to Done May 22, 2020
@lopezator
Copy link
Contributor Author

You are welcome @aeneasr !

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

Successfully merging this pull request may close these issues.

cockroachdb: consent query slow
4 participants