Skip to content
Snippets Groups Projects
Verified Commit ef870db3 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Declare the dependency between element type and corpus IDs in PostgreSQL stats

parent 70bbfa19
No related branches found
No related tags found
1 merge request!1998Declare the dependency between element type and corpus IDs in PostgreSQL stats
# Generated by Django 4.1.7 on 2023-05-23 12:42
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('documents', '0065_elementpath_constraints'),
]
operations = [
# This gives a hint to PostgreSQL's query planner that the element's corpus can be deduced from the type.
# If you filter by a specific type ID, then the corpus ID will be constant;
# all elements of the same type ID should be in the same corpus.
#
# This causes the query planner to create significantly better query plans when filtering by both corpus and type ID,
# as it understands that filtering on both type and corpus is the same as only filtering on the type,
# and the corpus filter will not reduce the planner's estimated row counts.
#
# On freshly created databases, this applies immediately. On existing databases, this will only have an effect after
# an autovacuum completes or after an administrator runs `ANALYZE documents_element`.
#
# See https://gitlab.com/teklia/arkindex/backend/-/issues/1309#note_1401556847 for context.
migrations.RunSQL(
"CREATE STATISTICS element_type_implies_corpus (dependencies) ON type_id, corpus_id FROM documents_element",
"DROP STATISTICS element_type_implies_corpus",
elidable=False,
),
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment