Re: Partition-wise join for join between (declaratively) partitioned tables
Robert Haas <robertmhaas@gmail.com>
On Mon, Mar 13, 2017 at 3:24 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> Haven't looked at 0007 yet.
+ if (rel->part_scheme)
+ {
+ int cnt_parts;
+
+ for (cnt_parts = 0; cnt_parts < nparts; cnt_parts++)
+ {
+ if (rel->part_oids[cnt_parts] ==
childRTE->relid)
+ {
+ Assert(!rel->part_rels[cnt_parts]);
+ rel->part_rels[cnt_parts] = childrel;
+ }
+ }
+ }
It's not very appealing to use an O(n^2) algorithm here. I wonder if
we could arrange things so that inheritance expansion expands
partitions in the right order, and then we could just match them up
one-to-one. This would probably require an alternate version of
find_all_inheritors() that expand_inherited_rtentry() would call only
for partitioned tables. Failing that, another idea would be to use
qsort() or qsort_arg() to put the partitions in the right order.
+ if (relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE ||
+ !inhparent ||
+ !(rel->part_scheme = find_partition_scheme(root, relation)))
Maybe just don't call this function in the first place in the
!inhparent case, instead of passing down an argument that must always
be true.
+ /* Match the partition key types. */
+ for (cnt_pks = 0; cnt_pks < partnatts; cnt_pks++)
+ {
+ /*
+ * For types, it suffices to match the type
id, mod and collation;
+ * len, byval and align are depedent on the first two.
+ */
+ if (part_key->partopfamily[cnt_pks] !=
part_scheme->partopfamily[cnt_pks] ||
+ part_key->partopcintype[cnt_pks] !=
part_scheme->partopcintype[cnt_pks] ||
+ part_key->parttypid[cnt_pks] !=
part_scheme->key_types[cnt_pks] ||
+ part_key->parttypmod[cnt_pks] !=
part_scheme->key_typmods[cnt_pks] ||
+ part_key->parttypcoll[cnt_pks] !=
part_scheme->key_collations[cnt_pks])
+ break;
+ }
I think memcmp() might be better than a for-loop.
Overall this one looks pretty good and straightforward. Of course, I
haven't looked at the main act (0009) yet.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Commits
-
Basic partition-wise join functionality.
- f49842d1ee31 11.0 landed
-
Assorted preparatory refactoring for partition-wise join.
- e139f1953f29 11.0 landed
-
Teach adjust_appendrel_attrs(_multilevel) to do multiple translations.
- 480f1f4329f1 11.0 landed
-
Stamp 10beta2.
- 42171e2cd23c 10.0 cited
-
Eat XIDs more efficiently in recovery TAP test.
- 08aed6604de2 10.0 cited
-
Abstract logic to allow for multiple kinds of child rels.
- 7a39b5e4d112 10.0 landed
-
Implement SortSupport for macaddr data type
- f90d23d0c518 10.0 cited
-
Attempt to stabilize grouping sets regression test plans.
- de4da168d57d 10.0 cited
-
Teach xlogreader to follow timeline switches
- 1148e22a82ed 10.0 cited
-
Don't scan partitioned tables.
- d3cc37f1d801 10.0 cited
-
Fix grammar.
- b4ff8609dbad 10.0 cited
-
postgres_fdw: Push down FULL JOINs with restriction clauses.
- b30fb56b07a8 10.0 cited
-
Some preliminary refactoring towards partitionwise join.
- c44c47a773bd 10.0 landed
-
contrib/amcheck needs RecentGlobalXmin to be PGDLLIMPORT'ified.
- 56018bf26eec 10.0 cited
-
Print test parameters like "foo: 123", and results like "foo = 123".
- 2a7f4f76434d 10.0 cited