Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

Commit45866c7

Browse files
committed
Copy information from the relcache instead of pointing to it.
We have the relations continuously locked, but not open, so relcachepointers are not guaranteed to be stable. Per buildfarm memberprion.Ashutosh Bapat. I fixed a typo.Discussion:http://postgr.es/m/CAFjFpRcRBqoKLZSNmRsjKr81uEP=ennvqSQaXVCCBTXvJ2rW+Q@mail.gmail.com
1 parenta1c2c43 commit45866c7

File tree

3 files changed

+96
-9
lines changed

3 files changed

+96
-9
lines changed

‎src/backend/catalog/partition.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,74 @@ partition_bounds_equal(int partnatts, int16 *parttyplen, bool *parttypbyval,
701701
return true;
702702
}
703703

704+
/*
705+
* Return a copy of given PartitionBoundInfo structure. The data types of bounds
706+
* are described by given partition key specificiation.
707+
*/
708+
externPartitionBoundInfo
709+
partition_bounds_copy(PartitionBoundInfosrc,
710+
PartitionKeykey)
711+
{
712+
PartitionBoundInfodest;
713+
inti;
714+
intndatums;
715+
intpartnatts;
716+
intnum_indexes;
717+
718+
dest= (PartitionBoundInfo)palloc(sizeof(PartitionBoundInfoData));
719+
720+
dest->strategy=src->strategy;
721+
ndatums=dest->ndatums=src->ndatums;
722+
partnatts=key->partnatts;
723+
724+
/* Range partitioned table has an extra index. */
725+
num_indexes=key->strategy==PARTITION_STRATEGY_RANGE ?ndatums+1 :ndatums;
726+
727+
/* List partitioned tables have only a single partition key. */
728+
Assert(key->strategy!=PARTITION_STRATEGY_LIST||partnatts==1);
729+
730+
dest->datums= (Datum**)palloc(sizeof(Datum*)*ndatums);
731+
732+
if (src->kind!=NULL)
733+
{
734+
dest->kind= (PartitionRangeDatumKind**)palloc(ndatums*
735+
sizeof(PartitionRangeDatumKind*));
736+
for (i=0;i<ndatums;i++)
737+
{
738+
dest->kind[i]= (PartitionRangeDatumKind*)palloc(partnatts*
739+
sizeof(PartitionRangeDatumKind));
740+
741+
memcpy(dest->kind[i],src->kind[i],
742+
sizeof(PartitionRangeDatumKind)*key->partnatts);
743+
}
744+
}
745+
else
746+
dest->kind=NULL;
747+
748+
for (i=0;i<ndatums;i++)
749+
{
750+
intj;
751+
dest->datums[i]= (Datum*)palloc(sizeof(Datum)*partnatts);
752+
753+
for (j=0;j<partnatts;j++)
754+
{
755+
if (dest->kind==NULL||
756+
dest->kind[i][j]==PARTITION_RANGE_DATUM_VALUE)
757+
dest->datums[i][j]=datumCopy(src->datums[i][j],
758+
key->parttypbyval[j],
759+
key->parttyplen[j]);
760+
}
761+
}
762+
763+
dest->indexes= (int*)palloc(sizeof(int)*num_indexes);
764+
memcpy(dest->indexes,src->indexes,sizeof(int)*num_indexes);
765+
766+
dest->null_index=src->null_index;
767+
dest->default_index=src->default_index;
768+
769+
returndest;
770+
}
771+
704772
/*
705773
* check_new_partition_bound
706774
*

‎src/backend/optimizer/util/plancat.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,13 +1825,15 @@ set_relation_partition_info(PlannerInfo *root, RelOptInfo *rel,
18251825
Relationrelation)
18261826
{
18271827
PartitionDescpartdesc;
1828+
PartitionKeypartkey;
18281829

18291830
Assert(relation->rd_rel->relkind==RELKIND_PARTITIONED_TABLE);
18301831

18311832
partdesc=RelationGetPartitionDesc(relation);
1833+
partkey=RelationGetPartitionKey(relation);
18321834
rel->part_scheme=find_partition_scheme(root,relation);
18331835
Assert(partdesc!=NULL&&rel->part_scheme!=NULL);
1834-
rel->boundinfo=partdesc->boundinfo;
1836+
rel->boundinfo=partition_bounds_copy(partdesc->boundinfo,partkey);
18351837
rel->nparts=partdesc->nparts;
18361838
set_baserel_partition_key_exprs(relation,rel);
18371839
}
@@ -1888,18 +1890,33 @@ find_partition_scheme(PlannerInfo *root, Relation relation)
18881890

18891891
/*
18901892
* Did not find matching partition scheme. Create one copying relevant
1891-
* information from the relcache.Instead of copying whole arrays, copy
1892-
* thepointers 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+
*sincetherelcache entry may not survive after we have closed the
1895+
*relation.
18941896
*/
18951897
part_scheme= (PartitionScheme)palloc0(sizeof(PartitionSchemeData));
18961898
part_scheme->strategy=partkey->strategy;
18971899
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);
19031920

19041921
/* Add the partitioning scheme to PlannerInfo. */
19051922
root->part_schemes=lappend(root->part_schemes,part_scheme);

‎src/include/catalog/partition.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ extern void RelationBuildPartitionDesc(Relation relation);
7474
externboolpartition_bounds_equal(intpartnatts,int16*parttyplen,
7575
bool*parttypbyval,PartitionBoundInfob1,
7676
PartitionBoundInfob2);
77+
externPartitionBoundInfopartition_bounds_copy(PartitionBoundInfosrc,
78+
PartitionKeykey);
7779

7880
externvoidcheck_new_partition_bound(char*relname,Relationparent,
7981
PartitionBoundSpec*spec);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp