On Mon, Mar 13, 2017 at 3:24 PM, Robert Haas <robertmh...@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 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers