-
Notifications
You must be signed in to change notification settings - Fork 1
Extremely poor performance on /api/importSourceLocations
#646
Comments
Lines 300 to 302 in 1a797e4
That can use |
From Discord:
|
That query running slow makes no sense, since it's against an index: CREATE UNIQUE INDEX core_concordanceidentifier_source_identifier_0ccc1cfe_uniq
ON public.concordance_identifier USING btree (authority, identifier) |
I built this dashboard to see if we need to vaccum - but it seems to indicate that the tables in question here have been auto-vacuumed recently: https://vial.calltheshots.us/dashboard/show-database-bloat/ |
Maybe we need to run |
with sqls as (select format('vacuum analyse %%I.%%I', n.nspname::varchar, t.relname::varchar) as sql FROM pg_class t JOIN pg_namespace n ON n.oid = t.relnamespace WHERE t.relkind = 'r' and n.nspname::varchar = 'public' order by 1)
select string_agg(sql, chr(59) || '
') || chr(59) from sqls |
These 3 sections of code are affected when there is a match action:
|
I'm going to run these: vacuum analyse public.api_log;
vacuum analyse public.source_location; -- took 15s
vacuum analyse public.source_location_match_history; -- took 154ms
vacuum analyse public.concordance_identifier; -- took 1.1s
vacuum analyse public.concordance_location; -- took 628ms
vacuum analyse public.concordance_source_location; -- took 526ms |
Are you running the UK version of Postgres? :)
|
Hah, TIL PostgreSQL speaks US and UK English! |
Since Velma matching still works, I suspect the problem is concordance updating. Velma does not update concordances (a separate problem), and so that is the biggest difference between import and update. |
This is the code most likely to be performing poorly: Lines 311 to 327 in d90d512
|
I'm suspicious of that |
I tried this in the debugger:
And got back this SQL: SELECT
"concordance_identifier"."id",
"concordance_identifier"."created_at",
"concordance_identifier"."authority",
"concordance_identifier"."identifier"
FROM
"concordance_identifier"
INNER JOIN "concordance_source_location" ON (
"concordance_identifier"."id" = "concordance_source_location"."concordanceidentifier_id"
)
WHERE
"concordance_source_location"."sourcelocation_id" = 5
EXCEPT
(
SELECT
"concordance_identifier"."id",
"concordance_identifier"."created_at",
"concordance_identifier"."authority",
"concordance_identifier"."identifier"
FROM
"concordance_identifier"
INNER JOIN "concordance_location" ON (
"concordance_identifier"."id" = "concordance_location"."concordanceidentifier_id"
)
WHERE
"concordance_location"."location_id" = 199
) |
|
Using primary keys could speed things up a lot. I need an efficient way to find the primary keys of the concordance identifiers which are on |
This is slightly more efficient: if matched_location is not None:
new_concordances = list(
source_location.concordances.values_list(
"pk", flat=True
).difference(matched_location.concordances.all())
)
matched_location.concordances.add(*new_concordances) |
@bryanculbertson says:
https://discord.com/channels/799147121357881364/813861006718926848/851940797959110706
The text was updated successfully, but these errors were encountered: