Add df.instances indexes for ordered listing (monitoring plan, PR 2)#271
Open
crprashant wants to merge 1 commit into
Open
Add df.instances indexes for ordered listing (monitoring plan, PR 2)#271crprashant wants to merge 1 commit into
crprashant wants to merge 1 commit into
Conversation
Add idx_instances_created_at (created_at DESC, id) to serve the unfiltered df.list_instances() listing, and replace the single-column idx_instances_status(status) with a composite (status, created_at DESC, id) for the status-filtered listing. Both let df.list_instances() return rows newest-first without a sort; the composite still covers the pending-instance scan via its leading status column. The trailing id positions the access path for the keyset pagination planned for a later PR; df.list_instances() does not order by id yet, so this does not change the current result ordering. Update the 0.2.3->0.2.4 upgrade script and upgrade-testing docs. The fresh-install and upgrade-chain index definitions are byte-identical (Scenario A). Part of the monitoring-functions plan (microsoft#167, microsoft#87, microsoft#146).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add/replace indexes on
df.instancesso thatdf.list_instances()can list rows in its natural order (newest-first) without a sort, on both the unfiltered and status-filtered paths:idx_instances_created_aton(created_at DESC, id)— serves the unfiltered listing... ORDER BY created_at DESC LIMIT, which previously had no supporting index.idx_instances_status(status)with the compositeidx_instances_status(status, created_at DESC, id)— serves the status-filtered listingWHERE status = $1 ORDER BY created_at DESC LIMITand still covers the pending-instance scan via the leadingstatuscolumn.The trailing
idprepares the access path for the keyset pagination planned for a later PR (ORDER BY created_at DESC, id ASC);df.list_instances()does not order byidyet, so this PR does not change the current result ordering.Files:
src/lib.rs(fresh-install DDL),sql/pg_durable--0.2.3--0.2.4.sql(upgrade DDL),docs/upgrade-testing.md(version-specific notes).Why
This is PR 2 of the agreed, incremental monitoring-functions plan on #167 (issues #87 and #146). Efficient ordered/paginated listing for external clients (#146) needs an index that matches the
ORDER BY created_at DESCaccess pattern; today the unfiltered path always sorts and the status-filtered path can't use the single-column status index for the sort.Design note (RLS)
df.instanceshas a row-level-security policy (instances_user_isolation) filteringsubmitted_by = current_user, so a per-user index leading withsubmitted_bywould be more selective for a single session. Thecreated_at-leading design is intentional: it is optimal for the admin / external-client global-listing path (#146) that reads across submitters, and still removes the per-query sort. Asubmitted_by-leading refinement can be revisited later if profiling shows the per-user path dominates.Upgrade & compatibility
DESCordering identical to the fresh-install DDL, sopg_get_indexdef()is byte-identical on both paths. Verified locally — both paths produceidx_instances_status … (status, created_at DESC, id)andidx_instances_created_at … (created_at DESC, id)..soissues the sameORDER BY created_at DESCqueries (referencing only existing columns) against older schemas; they stay correct and simply fall back to a sort untilALTER EXTENSION UPDATEis applied.DROP INDEX/CREATE INDEXrebuild access-path metadata only. TheCREATE INDEXbuilds take aSHARElock ondf.instances; on a large table, run the upgrade in a maintenance window.0.2.4is still unreleased, so the DDL is appended to the in-devsql/pg_durable--0.2.3--0.2.4.sql(no version bump, no new upgrade script).Scope
Indexes only — no changes to
df.list_instances()behavior or signature. The N+1 fix,label_filter+ keyset pagination, and the truncation policy land in subsequent PRs per the plan.cc @pinodeca