Background
In a previous optimization (PR #19), a redundant call to selected_or_default_graph_id_via_definer() was successfully removed from current_catalog_state(). This helped reduce the ~3.5ms unamortized fixed cost of graph traversals.
The Problem
However, looking closely at ensure_current_graph(), the very next line calls pending_sync_rows(applied_sync_id).
Tracing this call shows that it eventually hits SyncReplayContext::load(), which triggers a full read_catalog(). This means ensure_current_graph() is still doing a full redundant catalog read (including two massive SPI queries for _registered_tables and _registered_edges), completely undermining the optimization from PR #19.
Proposed Solution
Since ensure_current_graph() already loads catalog_state right before calling pending_sync_rows(), we can extract the applicable_table_oids from the loaded state and pass them directly to pending_sync_rows. This bypasses SyncReplayContext::load() entirely and eliminates the remaining redundant SPI queries from the hot path.
I will submit a PR with this fix shortly!
Background
In a previous optimization (PR #19), a redundant call to
selected_or_default_graph_id_via_definer()was successfully removed fromcurrent_catalog_state(). This helped reduce the ~3.5ms unamortized fixed cost of graph traversals.The Problem
However, looking closely at
ensure_current_graph(), the very next line callspending_sync_rows(applied_sync_id).Tracing this call shows that it eventually hits
SyncReplayContext::load(), which triggers a fullread_catalog(). This meansensure_current_graph()is still doing a full redundant catalog read (including two massive SPI queries for_registered_tablesand_registered_edges), completely undermining the optimization from PR #19.Proposed Solution
Since
ensure_current_graph()already loadscatalog_stateright before callingpending_sync_rows(), we can extract theapplicable_table_oidsfrom the loaded state and pass them directly topending_sync_rows. This bypassesSyncReplayContext::load()entirely and eliminates the remaining redundant SPI queries from the hot path.I will submit a PR with this fix shortly!