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

datastore: use UNION ALL for postgres list entries query #4111

Merged
merged 2 commits into from
Apr 27, 2023

Conversation

sorindumitru
Copy link
Contributor

@sorindumitru sorindumitru commented Apr 26, 2023

Pull Request check list

  • Commit conforms to CONTRIBUTING.md?
  • Proper tests/regressions included?
  • Documentation updated?

Affected functionality

Listing registration entries.

Description of change

This cuts the cost in time, as determined by EXPLAIN ANALYZE, in half. For a database with ~20000 entries and ~50000 selectors the time goes from ~200ms to ~100ms.

The difference between UNION and UNION ALL is that the former also does a DISTINCT step on the entries, removing any duplicates. It's possible I'm missing something simple, but I don't think that actually does anything for us here since most of the sub-queries also return an unique primary key so they are already unique.

Similar change can probably be done for the MySQL CTE query, but I haven't tested that yet. Can do that if this is considered an acceptable change.

This cuts the cost in time, as determined by EXPLAIN ANALYZE, in
half. For a database with ~20000 entries and ~50000 selectors the
time goes from ~200ms to ~100ms.

The difference between UNION and UNION ALL is that the former also
does a DISTINCT step on the entries, removing any duplicates. It's
possible I'm missing something simple, but I don't think that actually
does anything for us since most of the sub-queries also return an
unique primary key so they are already unique.

Signed-off-by: Sorin Dumitru <sdumitru@bloomberg.net>
Copy link
Collaborator

@rturner3 rturner3 left a comment

Choose a reason for hiding this comment

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

This looks good, nice catch @sorindumitru!

@rturner3 rturner3 merged commit 99a9445 into spiffe:main Apr 27, 2023
@rturner3 rturner3 added this to the 1.6.4 milestone Apr 27, 2023
d-goro pushed a commit to d-goro/spire that referenced this pull request May 18, 2023
This cuts the cost in time, as determined by EXPLAIN ANALYZE, in
half. For a database with ~20000 entries and ~50000 selectors the
time goes from ~200ms to ~100ms.

The difference between UNION and UNION ALL is that the former also
does a DISTINCT step on the entries, removing any duplicates. It's
possible I'm missing something simple, but I don't think that actually
does anything for us since most of the sub-queries also return an
unique primary key so they are already unique.

Signed-off-by: Sorin Dumitru <sdumitru@bloomberg.net>
Signed-off-by: Dmitry Gorochovsky <d.goro@yahoo.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.

2 participants