Skip to content

graph, store: Mirror source indexes on copy/graft - #6762

Draft
dimitrovmaksim wants to merge 2 commits into
fix/copy-postponed-indexes-flagfrom
fix/copy-mirror-source-indexes
Draft

dimitrovmaksim wants to merge 2 commits into
fix/copy-postponed-indexes-flagfrom
fix/copy-mirror-source-indexes

Conversation

@dimitrovmaksim

@dimitrovmaksim dimitrovmaksim commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #6722

Stacked on #6761. Review the last two commits only.

Since #6434, a copy or graft created the indexes it gets with its tables from its own layout instead of from its source. Indexes dropped on the source came back, and manual indexes were lost.

Commits

  • store: Ignore invalid indexes of a copy source. A copy now reads only the source's valid indexes. An index is invalid while a concurrent build is running, or after a concurrent build or drop failed or was interrupted. Before, a copy rebuilt postponed indexes an operator was dropping, or whose build had failed on the source. Dumps still read all indexes.

  • graph, store: Mirror source indexes on copy/graft. A copy or graft gets the indexes its source has, for each source table with the same mutability:

    • graph-node's own indexes come from the layout, even where the source tuned them.
    • Its attribute indexes are left out where the source has their columns but doesn't index them.
    • A source index under a graph-node name is copied only when the table has its columns but doesn't index them, such as a GIN index on a list.
    • Other source indexes are copied with the statement Postgres prints for them, with only the schema name changed, each in its own savepoint. Those that can't be copied are logged with the reason.
    • Tables that are new or changed mutability get the layout's indexes.

    GRAPH_STORE_COPY_MIRROR_INDEXES (default true) turns this off.

Tests

New graft tests in store/test-store/tests/postgres/graft.rs and DDL tests in store/postgres/src/relational/ddl_tests.rs.

A copy took every index of the source into account, including invalid
ones. An index is invalid when a concurrent build or drop of it failed
or was interrupted, and while a concurrent build is still running. A
copy rebuilt postponed indexes that an operator was dropping, or whose
build had failed on the source.

A copy now reads only the source's valid indexes. Dumps still read all
of them, since they record the schema as it is.
Since #6434, a copy or graft created the indexes it gets with its tables
from its own layout instead of from its source. Indexes dropped on the
source came back, and manual indexes were lost. Before #6434, a copy
followed its source only when postponement was on.

A copy or graft now gets the indexes its source has, for each table the
source has with the same mutability. graph-node's own indexes come from
the layout, even where the source tuned them, and its attribute indexes
are left out where the source has their columns but doesn't index them.
A source index under a graph-node name is copied only when the table
has its columns but doesn't index them, such as a GIN index on a list.
The source's other indexes are copied with the statement Postgres
prints for them, with only the schema name changed, each in its own
savepoint. Those that can't be copied are logged with the reason. Tables
that are new or changed mutability get the layout's indexes, also at
the end of the copy.

GRAPH_STORE_COPY_MIRROR_INDEXES, true by default, turns this off.

Fixes #6722
@dimitrovmaksim
dimitrovmaksim force-pushed the fix/copy-mirror-source-indexes branch from 0ba00f3 to 2b2c548 Compare November 10, 2026 13:53

This branch has not been deployed

No deployments
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.

graphman copy: since v0.44.0 the destination gets the layout's GiST/id indexes regardless of the source's index set (#5140 / #5425)

1 participant