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

Slow schema loading on UI for big databases #627

Open
vicmarbev opened this issue Jan 2, 2025 · 1 comment
Open

Slow schema loading on UI for big databases #627

vicmarbev opened this issue Jan 2, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@vicmarbev
Copy link

Hi! We've noticed that the schema loading in the UI for tables with a lot of constraints, for example with Sentry's self hosted PostgreSQL database. The querythat seems to do the heavy lifting in this case is the one that gets the primary key constraints and for us takes around 10-12 seconds:

 SELECT
    c.table_schema,
    c.table_name,
    c.column_name
  FROM information_schema.table_constraints tc
  JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
  JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema
    AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
  WHERE constraint_type = 'PRIMARY KEY'

image

Toying with it I think that we can omit the the information_schema.columns join as we have all the information that we need in the information_schema.constraint_column_usage table. This query for this table takes us around 1 second:

SELECT
    ccu.constraint_schema AS table_schema,
    ccu.table_name,
    ccu.column_name
FROM information_schema.constraint_column_usage AS ccu
JOIN information_schema.table_constraints AS tc 
    ON ccu.constraint_schema = tc.constraint_schema
    AND ccu.constraint_name = tc.constraint_name
WHERE tc.constraint_type = 'PRIMARY KEY';

image

What do you think? Would this work or could we miss something with this second query?

@feraio
Copy link

feraio commented Jan 3, 2025

Hello @vicmarbev, thanks for opening this issue.
I'll take your case to the engineering team to test and evaluate it.

I let you know as soon as we have any updates.

@sandromello sandromello added the enhancement New feature or request label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants