Re: UPDATE of partition key
Robert Haas <robertmhaas@gmail.com>
Attachments
- decide-whether-we-need-update-tuple-routing.patch (application/octet-stream) patch
On Thu, Jun 29, 2017 at 3:52 PM, Amit Khandekar <amitdkhan.pg@gmail.com> wrote: > So to conclude, I think, we can do this : > > Scenario 1 : > Only one partitioned table : the root; rest all are leaf partitions. > In this case, it is definitely efficient to just check the root > partition key, which will be sufficient. > > Scenario 2 : > There are few non-leaf partitioned tables (3-4) : > Open those tables, and follow 2nd approach above: If we don't find any > updated partition-keys in any of them, well and good. If we do find, > failover to approach 3 : For each of the update resultrels, use the > new rd_partcheckattrs bitmap to know if it uses any of the updated > columns. This would be faster than pulling up attrs from the quals > like how it was done in the patch. I think we should just have the planner figure out a list of which columns are partitioning columns either for the named relation or some descendent, and set a flag if that set of columns overlaps the set of columns updated. At execution time, update tuple routing is needed if either that flag is set or if some partition included in the plan has a BR UPDATE trigger. Attached is a draft patch implementing that approach. This could be made more more accurate. Suppose table foo is partitioned by a and some but not all of the partitions partitioned by b. If it so happens that, in a query which only updates b, constraint exclusion eliminates all of the partitions that are subpartitioned by b, it would be unnecessary to enable update tuple routing (unless BR UPDATE triggers are present) but this patch will not figure that out. I don't think that optimization is critical for the first version of this feature; there will be a limited number of users with asymmetrical subpartitioning setups, and if one of them has an idea how to improve this without hurting anything else, they are free to contribute a patch. Other optimizations are possible too, but I don't really see any of them as critical either. I don't think the approach of building a hash table to figure out which result rels have already been created is a good one. That too feels like something that the planner should be figuring out and the executor should just be implementing what the planner decided. I haven't figured out exactly how that should work yet, but it seems like it ought to be doable. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Commits
-
Avoid referencing off the end of subplan_partition_offsets.
- 945f71db8452 11.0 landed
-
Allow UPDATE to move rows between partitions.
- 2f178441044b 11.0 landed
-
Remove useless lookup of root partitioned rel in ExecInitModifyTable().
- dca48d145e0e 11.0 cited
-
Factor error generation out of ExecPartitionCheck.
- 19c47e7c8202 11.0 landed
-
Minor preparatory refactoring for UPDATE row movement.
- ef6087ee5fa8 11.0 landed
-
Simplify and encapsulate tuple routing support code.
- cc6337d2fed5 11.0 landed
-
Avoid coercing a whole-row variable that is already coerced.
- 1c497fa72df7 11.0 landed
-
Use ResultRelInfo ** rather than ResultRelInfo * for tuple routing.
- 60f7c0abef03 11.0 landed
-
Make RelationGetPartitionDispatchInfo expand depth-first.
- 77b6b5e9ceca 11.0 cited
-
Expand partitioned tables in PartDesc order.
- 30833ba154e0 11.0 cited
-
Use a real RT index when setting up partition tuple routing.
- f81a91db4d1c 10.0 cited
-
Fix transition tables for partition/inheritance.
- 501ed02cf6f4 10.0 cited
-
Fix confusion about number of subplans in partitioned INSERT setup.
- 78a030a44196 10.0 cited
-
Prevent BEFORE triggers from violating partitioning constraints.
- 15ce775faa42 10.0 cited
-
Fire per-statement triggers on partitioned tables.
- e180c8aa8caf 10.0 cited
-
Fix reporting of violations in ExecConstraints, again.
- c0a8ae7be392 10.0 cited
-
Don't scan partitioned tables.
- d3cc37f1d801 10.0 cited
-
Allow FDWs to push down quals without breaking EvalPlanQual rechecks.
- 5fc4c26db512 9.6.0 cited