Skip to content

Commit

Permalink
Fix very slow global introspection query when there are lots of datab…
Browse files Browse the repository at this point in the history
…ases (#6633)

The introspection query was fetching annotations, which can never be
populated on databases and which was exhibiting some pretty
pathological quadratic time introspection queries. With 500 dbs,
it took me about 30s.

Also add a new knob to the patch system so that we can apply this in a
patch without it needing to do anything expensive on each database.
  • Loading branch information
msullivan authored Dec 22, 2023
1 parent ec8e38e commit c3e3296
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions edb/schema/reflection/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,21 @@ def generate_structure(
sn.UnqualName(f'{refdict.attr}__internal'),
)

# HACK: sys::Database is an AnnotationSubject, but
# there is no way to actually put annotations on it,
# and fetching them results in some pathological
# quadratic queries where each inner iteration does
# expensive fetching of metadata and JSON decoding.
# Override it to return nothing.
# TODO: For future versions, we can probably just
# drop it.
if (
str(rschema_name) == 'sys::Database'
and refdict.attr == 'annotations'
):
props = {}
read_ptr = f'{read_ptr} := <schema::AnnotationValue>{{}}'

for field in props:
sfn = field.sname
prop_shape_els.append(f'@{sfn}')
Expand Down
3 changes: 2 additions & 1 deletion edb/server/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ def prepare_patch(
updates: dict[str, Any] = {}

global_schema_update = kind == 'ext-pkg'
sys_update_only = global_schema_update or kind.endswith('+globalonly')

if kind == 'ext-pkg':
# N.B: We process this without actually having the global
Expand Down Expand Up @@ -1025,7 +1026,7 @@ def prepare_patch(
# perhaps), only run the script once, on the system connection.
# Since the state is global, we only should update it once.
regular_updates: tuple[str, ...]
if global_schema_update:
if sys_update_only:
regular_updates = (update,)
sys_updates = (patch,) + sys_updates
else:
Expand Down

0 comments on commit c3e3296

Please sign in to comment.