mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Code review focused on new node types added by partitioning support.
Fix failure to check that we got a plain Const from const-simplification of a coercion request. This is the cause of bug #14666 from Tian Bing: there is an int4 to money cast, but it's only stable not immutable (because of dependence on lc_monetary), resulting in a FuncExpr that the code was miserably unequipped to deal with, or indeed even to notice that it was failing to deal with. Add test cases around this coercion behavior. In view of the above, sprinkle the code liberally with castNode() macros, in hope of catching the next such bug a bit sooner. Also, change some functions that were randomly declared to take Node* to take more specific pointer types. And change some struct fields that were declared Node* but could be given more specific types, allowing removal of assorted explicit casts. Place PARTITION_MAX_KEYS check a bit closer to the code it's protecting. Likewise check only-one-key-for-list-partitioning restriction in a less random place. Avoid not-per-project-style usages like !strcmp(...). Fix assorted failures to avoid scribbling on the input of parse transformation. I'm not sure how necessary this is, but it's entirely silly for these functions to be expending cycles to avoid that and not getting it right. Add guards against partitioning on system columns. Put backend/nodes/ support code into an order that matches handling of these node types elsewhere. Annotate the fact that somebody added location fields to PartitionBoundSpec and PartitionRangeDatum but forgot to handle them in outfuncs.c/readfuncs.c. This is fairly harmless for production purposes (since readfuncs.c would just substitute -1 anyway) but it's still bogus. It's not worth forcing a post-beta1 initdb just to fix this, but if we have another reason to force initdb before 10.0, we should go back and clean this up. Contrariwise, somebody added location fields to PartitionElem and PartitionSpec but forgot to teach exprLocation() about them. Consolidate duplicative code in transformPartitionBound(). Improve a couple of error messages. Improve assorted commentary. Re-pgindent the files touched by this patch; this affects a few comment blocks that must have been added quite recently. Report: https://postgr.es/m/20170524024550.29935.14396@wrigleys.postgresql.org
This commit is contained in:
@@ -755,7 +755,10 @@ typedef struct XmlSerialize
|
||||
/* Partitioning related definitions */
|
||||
|
||||
/*
|
||||
* PartitionElem - a column in the partition key
|
||||
* PartitionElem - parse-time representation of a single partition key
|
||||
*
|
||||
* expr can be either a raw expression tree or a parse-analyzed expression.
|
||||
* We don't store these on-disk, though.
|
||||
*/
|
||||
typedef struct PartitionElem
|
||||
{
|
||||
@@ -768,7 +771,9 @@ typedef struct PartitionElem
|
||||
} PartitionElem;
|
||||
|
||||
/*
|
||||
* PartitionSpec - partition key specification
|
||||
* PartitionSpec - parse-time representation of a partition key specification
|
||||
*
|
||||
* This represents the key space we will be partitioning on.
|
||||
*/
|
||||
typedef struct PartitionSpec
|
||||
{
|
||||
@@ -778,52 +783,55 @@ typedef struct PartitionSpec
|
||||
int location; /* token location, or -1 if unknown */
|
||||
} PartitionSpec;
|
||||
|
||||
/* Internal codes for partitioning strategies */
|
||||
#define PARTITION_STRATEGY_LIST 'l'
|
||||
#define PARTITION_STRATEGY_RANGE 'r'
|
||||
|
||||
/*
|
||||
* PartitionBoundSpec - a partition bound specification
|
||||
*
|
||||
* This represents the portion of the partition key space assigned to a
|
||||
* particular partition. These are stored on disk in pg_class.relpartbound.
|
||||
*/
|
||||
typedef struct PartitionBoundSpec
|
||||
{
|
||||
NodeTag type;
|
||||
|
||||
char strategy;
|
||||
char strategy; /* see PARTITION_STRATEGY codes above */
|
||||
|
||||
/* List partition values */
|
||||
List *listdatums;
|
||||
/* Partitioning info for LIST strategy: */
|
||||
List *listdatums; /* List of Consts (or A_Consts in raw tree) */
|
||||
|
||||
/*
|
||||
* Range partition lower and upper bounds; each member of the lists is a
|
||||
* PartitionRangeDatum (see below).
|
||||
*/
|
||||
List *lowerdatums;
|
||||
List *upperdatums;
|
||||
/* Partitioning info for RANGE strategy: */
|
||||
List *lowerdatums; /* List of PartitionRangeDatums */
|
||||
List *upperdatums; /* List of PartitionRangeDatums */
|
||||
|
||||
int location;
|
||||
int location; /* token location, or -1 if unknown */
|
||||
} PartitionBoundSpec;
|
||||
|
||||
/*
|
||||
* PartitionRangeDatum
|
||||
* PartitionRangeDatum - can be either a value or UNBOUNDED
|
||||
*
|
||||
* "value" is an A_Const in raw grammar output, a Const after analysis
|
||||
*/
|
||||
typedef struct PartitionRangeDatum
|
||||
{
|
||||
NodeTag type;
|
||||
|
||||
bool infinite;
|
||||
Node *value;
|
||||
bool infinite; /* true if UNBOUNDED */
|
||||
Node *value; /* null if UNBOUNDED */
|
||||
|
||||
int location;
|
||||
int location; /* token location, or -1 if unknown */
|
||||
} PartitionRangeDatum;
|
||||
|
||||
/*
|
||||
* PartitionCmd - ALTER TABLE partition commands
|
||||
* PartitionCmd - info for ALTER TABLE ATTACH/DETACH PARTITION commands
|
||||
*/
|
||||
typedef struct PartitionCmd
|
||||
{
|
||||
NodeTag type;
|
||||
RangeVar *name;
|
||||
Node *bound;
|
||||
RangeVar *name; /* name of partition to attach/detach */
|
||||
PartitionBoundSpec *bound; /* FOR VALUES, if attaching */
|
||||
} PartitionCmd;
|
||||
|
||||
/****************************************************************************
|
||||
@@ -1969,7 +1977,7 @@ typedef struct CreateStmt
|
||||
List *tableElts; /* column definitions (list of ColumnDef) */
|
||||
List *inhRelations; /* relations to inherit from (list of
|
||||
* inhRelation) */
|
||||
Node *partbound; /* FOR VALUES clause */
|
||||
PartitionBoundSpec *partbound; /* FOR VALUES clause */
|
||||
PartitionSpec *partspec; /* PARTITION BY clause */
|
||||
TypeName *ofTypename; /* OF typename */
|
||||
List *constraints; /* constraints (list of Constraint nodes) */
|
||||
|
||||
Reference in New Issue
Block a user