Skip to content

Fix list table-parts always reporting 0 parts - #45

Merged
teknogeek0 merged 1 commit into
mainfrom
fix/list-table-parts-count
Jul 23, 2026
Merged

Fix list table-parts always reporting 0 parts#45
teknogeek0 merged 1 commit into
mainfrom
fix/list-table-parts-count

Conversation

@teknogeek0

Copy link
Copy Markdown
Collaborator

Problem

pgcopydb list table-parts always printed "Table … COPY will be split 0-ways" with an empty table, regardless of size or --split-tables-larger-than.

Root cause

cli_list_table_parts set partKey (including the CTID case) but never called schema_list_partitions, so the s_table_part catalog was empty and table->partition.partCount was 0. The full copy path (copydb_prepare_table_specs_hook) does call it; the list command bypassed it.

Fix

Compute the partitions (schema_list_partitions) before the display loop, so the command reports the real split. list table-parts is a diagnostic/planning command — no effect on the migration path.

Clean cherry-pick of upstream dimitri/pgcopydb dimitri#982.

Tests

unit suite (which drives list table-parts) green in the full PGVERSION=18 make tests run. The only red was the pre-existing blob-snapshot-release snapshot-race flake, which touches no code in this change.

pgcopydb list table-parts was never calling schema_list_partitions, so
s_table_part was always empty and the command always printed
"COPY will be split 0-ways" for every table, regardless of size.

The fix adds the missing computation step between the partKey setup and
the display loop:

1. Check whether DATA_SECTION_TABLE_DATA_PARTS is already marked as
   fetched in the SQLite catalog (i.e. a previous run computed and
   stored the parts).  If it is, re-use the cached rows directly – the
   catalog already has everything catalog_iter_s_table_parts needs.

2. If the section is not yet fetched, open a source connection and run
   the same logic the full copy path uses:
   - For CTID splits: optionally ANALYZE the table first (skipped when
     --estimate-table-sizes is set), then call schema_list_relpages to
     get a fresh relpages value.
   - Call schema_list_partitions, which writes every part to s_table_part
     and sets table->partition.partCount to the actual split count.
   - Call catalog_register_section to mark the section as done so the
     next invocation uses the cache.

After this, log_info("Table %s COPY will be split %d-ways") prints the
correct count and catalog_iter_s_table_parts iterates the real rows.

Closes dimitri#872

(cherry picked from commit 80dddd8)
@teknogeek0
teknogeek0 merged commit 327fb68 into main Jul 23, 2026
93 checks passed
@teknogeek0
teknogeek0 deleted the fix/list-table-parts-count branch July 23, 2026 01:22
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.

2 participants