Commit c8151e64 authored by Tom Lane's avatar Tom Lane

Don't copy PartitionBoundInfo in set_relation_partition_info.

I (tgl) remain dubious that it's a good idea for PartitionDirectory
to hold a pin on a relcache entry throughout planning, rather than
copying the data or using some kind of refcount scheme.  However, it's
certainly the responsibility of the PartitionDirectory code to ensure
that what it's handing back is a stable data structure, not that of
its caller.  So this is a pretty clear oversight in commit 898e5e32,
and one that can cost a lot of performance when there are many
partitions.

Amit Langote (extracted from a much larger patch set)

Discussion: https://postgr.es/m/CA+TgmoY3bRmGB6-DUnoVy5fJoreiBJ43rwMrQRCdPXuKt4Ykaw@mail.gmail.com
Discussion: https://postgr.es/m/9d7c5112-cb99-6a47-d3be-cf1ee6862a1d@lab.ntt.co.jp
parent b5fd4972
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#include "optimizer/optimizer.h" #include "optimizer/optimizer.h"
#include "optimizer/plancat.h" #include "optimizer/plancat.h"
#include "optimizer/prep.h" #include "optimizer/prep.h"
#include "partitioning/partbounds.h"
#include "partitioning/partdesc.h" #include "partitioning/partdesc.h"
#include "parser/parse_relation.h" #include "parser/parse_relation.h"
#include "parser/parsetree.h" #include "parser/parsetree.h"
...@@ -2082,16 +2081,14 @@ set_relation_partition_info(PlannerInfo *root, RelOptInfo *rel, ...@@ -2082,16 +2081,14 @@ set_relation_partition_info(PlannerInfo *root, RelOptInfo *rel,
Relation relation) Relation relation)
{ {
PartitionDesc partdesc; PartitionDesc partdesc;
PartitionKey partkey;
Assert(relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE); Assert(relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
partdesc = PartitionDirectoryLookup(root->glob->partition_directory, partdesc = PartitionDirectoryLookup(root->glob->partition_directory,
relation); relation);
partkey = RelationGetPartitionKey(relation);
rel->part_scheme = find_partition_scheme(root, relation); rel->part_scheme = find_partition_scheme(root, relation);
Assert(partdesc != NULL && rel->part_scheme != NULL); Assert(partdesc != NULL && rel->part_scheme != NULL);
rel->boundinfo = partition_bounds_copy(partdesc->boundinfo, partkey); rel->boundinfo = partdesc->boundinfo;
rel->nparts = partdesc->nparts; rel->nparts = partdesc->nparts;
set_baserel_partition_key_exprs(relation, rel); set_baserel_partition_key_exprs(relation, rel);
rel->partition_qual = RelationGetPartitionQual(relation); rel->partition_qual = RelationGetPartitionQual(relation);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment