Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fbd4321

Browse filesBrowse files
committed
Don't copy extended statistics during MERGE/SPLIT partition operations
When MERGE/SPLIT created new partitions, it was cloning the extended statistics of the parent table. However, extended stats on partitioned tables don't behave like indexes on partitioned tables (which exist only to create physical indexes on child tables). Rather, extended stats on a parent 1) cause extended stats to be collected and computed across the whole partition hierarchy, and 2) do not cause extended stats to be computed for the individual partitions. "CREATE TABLE ... PARTITION OF" command doesn't copy extended statistics. This commit makes createPartitionTable() behave consistently. Reported-by: Justin Pryzby Discussion: https://postgr.es/m/ZiJW1g2nbQs9ekwK%40pryzbyj2023 Author: Alexander Korotkov, Justin Pryzby
1 parent 3a82c68 commit fbd4321
Copy full SHA for fbd4321

File tree

2 files changed

+12
-5
lines changed
Filter options

2 files changed

+12
-5
lines changed

‎doc/src/sgml/ref/alter_table.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/ref/alter_table.sgml
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,12 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
11541154
</para>
11551155
<para>
11561156
The new partitions will be created the same as tables created with the
1157-
SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_nameN</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
1157+
SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_nameN</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY EXCLUDING STATISTICS)</literal>.
11581158
The indexes and identity are created later, after moving the data
11591159
into the new partitions.
1160+
Extended statistics aren't copied from the parent table, for consistency with
1161+
<command>CREATE TABLE PARTITION OF</command>.
1162+
11601163
New partitions will have the same table access method as the parent.
11611164
If the parent table is persistent then new partitions are created
11621165
persistent. If the parent table is temporary then new partitions
@@ -1224,9 +1227,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
12241227
</para>
12251228
<para>
12261229
The new partition will be created the same as a table created with the
1227-
SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_name</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
1230+
SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_name</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY EXCLUDING STATISTICS)</literal>.
12281231
The indexes and identity are created later, after moving the data
12291232
into the new partition.
1233+
Extended statistics aren't copied from the parent table, for consistency with
1234+
<command>CREATE TABLE PARTITION OF</command>.
12301235
The new partition will have the same table access method as the parent.
12311236
If the parent table is persistent then the new partition is created
12321237
persistent. If the parent table is temporary then the new partition

‎src/backend/commands/tablecmds.c

Copy file name to clipboardExpand all lines: src/backend/commands/tablecmds.c
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20269,7 +20269,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
2026920269
* (newPartName) like table (modelRel)
2027020270
*
2027120271
* Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRel's name>
20272-
* INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
20272+
* INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY EXCLUDING STATISTICS)
2027320273
*
2027420274
* Also, this function sets the new partition access method same as parent
2027520275
* table access methods (similarly to CREATE TABLE ... PARTITION OF). It
@@ -20313,9 +20313,11 @@ createPartitionTable(RangeVar *newPartName, Relation modelRel,
2031320313

2031420314
/*
2031520315
* Indexes will be inherited on "attach new partitions" stage, after data
20316-
* moving.
20316+
* moving. We also don't copy the extended statistics for consistency
20317+
* with CREATE TABLE PARTITION OF.
2031720318
*/
20318-
tlc->options = CREATE_TABLE_LIKE_ALL & ~(CREATE_TABLE_LIKE_INDEXES | CREATE_TABLE_LIKE_IDENTITY);
20319+
tlc->options = CREATE_TABLE_LIKE_ALL &
20320+
~(CREATE_TABLE_LIKE_INDEXES | CREATE_TABLE_LIKE_IDENTITY | CREATE_TABLE_LIKE_STATISTICS);
2031920321
tlc->relationOid = InvalidOid;
2032020322
createStmt->tableElts = lappend(createStmt->tableElts, tlc);
2032120323

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.