| The PostgreSQL 9.0 Reference Manual - Volume 1A - SQL Language Reference
by The PostgreSQL Global Development Group Paperback (6"x9"), 454 pages ISBN 9781906966041 RRP £14.95 ($19.95) Sales of this book support the PostgreSQL project! Get a printed copy>>> |
3.9.6 Caveats
The following caveats apply to partitioned tables:
-
There is no automatic way to verify that all of the
CHECKconstraints are mutually exclusive. It is safer to create code that generates partitions and creates and/or modifies associated objects than to write each by hand. -
The schemes shown here assume that the partition key column(s)
of a row never change, or at least do not change enough to require
it to move to another partition. An
UPDATEthat attempts to do that will fail because of theCHECKconstraints. If you need to handle such cases, you can put suitable update triggers on the partition tables, but it makes management of the structure much more complicated. -
If you are using manual
VACUUMorANALYZEcommands, don't forget that you need to run them on each partition individually. A command like:ANALYZE measurement;
will only process the master table.
The following caveats apply to constraint exclusion:
-
Constraint exclusion only works when the query's
WHEREclause contains constants. A parameterized query will not be optimized, since the planner cannot know which partitions the parameter value might select at run time. For the same reason, “stable” functions such asCURRENT_DATEmust be avoided. - Keep the partitioning constraints simple, else the planner may not be able to prove that partitions don't need to be visited. Use simple equality conditions for list partitioning, or simple range tests for range partitioning, as illustrated in the preceding examples. A good rule of thumb is that partitioning constraints should contain only comparisons of the partitioning column(s) to constants using B-tree-indexable operators.
- All constraints on all partitions of the master table are examined during constraint exclusion, so large numbers of partitions are likely to increase query planning time considerably. Partitioning using these techniques will work well with up to perhaps a hundred partitions; don't try to use many thousands of partitions.
| ISBN 9781906966041 | The PostgreSQL 9.0 Reference Manual - Volume 1A - SQL Language Reference | See the print edition |