@@ -1825,13 +1825,15 @@ set_relation_partition_info(PlannerInfo *root, RelOptInfo *rel,
1825
1825
Relation relation )
1826
1826
{
1827
1827
PartitionDesc partdesc ;
1828
+ PartitionKey partkey ;
1828
1829
1829
1830
Assert (relation -> rd_rel -> relkind == RELKIND_PARTITIONED_TABLE );
1830
1831
1831
1832
partdesc = RelationGetPartitionDesc (relation );
1833
+ partkey = RelationGetPartitionKey (relation );
1832
1834
rel -> part_scheme = find_partition_scheme (root , relation );
1833
1835
Assert (partdesc != NULL && rel -> part_scheme != NULL );
1834
- rel -> boundinfo = partdesc -> boundinfo ;
1836
+ rel -> boundinfo = partition_bounds_copy ( partdesc -> boundinfo , partkey ) ;
1835
1837
rel -> nparts = partdesc -> nparts ;
1836
1838
set_baserel_partition_key_exprs (relation , rel );
1837
1839
}
@@ -1888,18 +1890,33 @@ find_partition_scheme(PlannerInfo *root, Relation relation)
1888
1890
1889
1891
/*
1890
1892
* Did not find matching partition scheme. Create one copying relevant
1891
- * information from the relcache. Instead of copying whole arrays, copy
1892
- * the pointers in relcache. It's safe to do so since
1893
- * RelationClearRelation() wouldn't change it while planner is using it .
1893
+ * information from the relcache. We need to copy the contents of the array
1894
+ * since the relcache entry may not survive after we have closed the
1895
+ * relation .
1894
1896
*/
1895
1897
part_scheme = (PartitionScheme ) palloc0 (sizeof (PartitionSchemeData ));
1896
1898
part_scheme -> strategy = partkey -> strategy ;
1897
1899
part_scheme -> partnatts = partkey -> partnatts ;
1898
- part_scheme -> partopfamily = partkey -> partopfamily ;
1899
- part_scheme -> partopcintype = partkey -> partopcintype ;
1900
- part_scheme -> parttypcoll = partkey -> parttypcoll ;
1901
- part_scheme -> parttyplen = partkey -> parttyplen ;
1902
- part_scheme -> parttypbyval = partkey -> parttypbyval ;
1900
+
1901
+ part_scheme -> partopfamily = (Oid * ) palloc (sizeof (Oid ) * partnatts );
1902
+ memcpy (part_scheme -> partopfamily , partkey -> partopfamily ,
1903
+ sizeof (Oid ) * partnatts );
1904
+
1905
+ part_scheme -> partopcintype = (Oid * ) palloc (sizeof (Oid ) * partnatts );
1906
+ memcpy (part_scheme -> partopcintype , partkey -> partopcintype ,
1907
+ sizeof (Oid ) * partnatts );
1908
+
1909
+ part_scheme -> parttypcoll = (Oid * ) palloc (sizeof (Oid ) * partnatts );
1910
+ memcpy (part_scheme -> parttypcoll , partkey -> parttypcoll ,
1911
+ sizeof (Oid ) * partnatts );
1912
+
1913
+ part_scheme -> parttyplen = (int16 * ) palloc (sizeof (int16 ) * partnatts );
1914
+ memcpy (part_scheme -> parttyplen , partkey -> parttyplen ,
1915
+ sizeof (int16 ) * partnatts );
1916
+
1917
+ part_scheme -> parttypbyval = (bool * ) palloc (sizeof (bool ) * partnatts );
1918
+ memcpy (part_scheme -> parttypbyval , partkey -> parttypbyval ,
1919
+ sizeof (bool ) * partnatts );
1903
1920
1904
1921
/* Add the partitioning scheme to PlannerInfo. */
1905
1922
root -> part_schemes = lappend (root -> part_schemes , part_scheme );
0 commit comments