Skip to content

feat(perf): skip redundant DDL checks in SQLSampleStore.__init__#670

Open
michael-johnston wants to merge 1 commit intomainfrom
maj_skip_redundant_ddl_checks
Open

feat(perf): skip redundant DDL checks in SQLSampleStore.__init__#670
michael-johnston wants to merge 1 commit intomainfrom
maj_skip_redundant_ddl_checks

Conversation

@michael-johnston
Copy link
Member

Previously, SQLSampleStore.init called _create_source_table() unconditionally on every construction. _create_source_table() calls meta.create_all(checkfirst=True), which issues a separate table-existence query for each of the four backing tables even when the tables already exist — which they always do on read-only CLI commands. Locally this cost was ~1.45s. The changes reduce this to 0.24s.

The main fix is to probe for table existence instead of blinding issuing _create_source_tables(). This removes the 1.45 and adds the probe. We use a direct SQL probe (taking 240ms locally measured) instead of sqlalchemy.inspect() which took 800ms locally.

The PR also introduces a process-level _source_tables_verified that records tablename prefixes whose backing tables have already been confirmed to exist.
On the second and subsequent SQLSampleStore constructions for the same store within the same process the probe is skipped entirely (0 round-trips).
The main impact of this is in the tests.

Previously, SQLSampleStore.__init__ called _create_source_table()
unconditionally on every construction.  _create_source_table() calls
meta.create_all(checkfirst=True), which issues a separate table-existence
query for each of the four backing tables even when
the tables already exist — which they always do on read-only CLI commands.
Locally this cost was ~1.45s. The changes reduce this to 0.24s.

The main fix is to probe for table existence instead of blinding issuing _create_source_tables(). This removes the 1.45 and adds the probe. We use a direct SQL probe (taking 240ms locally measured) instead of sqlalchemy.inspect() which took 800ms locally.

 The PR also introduces a process-level _source_tables_verified that records tablename prefixes whose backing tables have already been confirmed to exist.
  On the second and subsequent SQLSampleStore constructions for the same store within the same process the probe is skipped entirely (0 round-trips).
  The main impact of this is in the tests.
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.

1 participant