@@ -84,11 +84,13 @@ static void postprocess_child_table_and_atts(Oid parent_relid, Oid partition_rel
8484static Oid text_to_regprocedure (text * proname_args );
8585
8686static Constraint * make_constraint_common (char * name ,Node * raw_expr );
87- static Node * get_constraint_expression (Oid parent_relid ,
88- Oid * expr_type ,List * * columns );
8987static Value make_string_value_struct (char * str );
9088static Value make_int_value_struct (int int_val );
9189
90+ static Node * get_partitioning_expression (Oid parent_relid ,
91+ Oid * expr_type ,
92+ List * * columns );
93+
9294/*
9395 * ---------------------------------------
9496 * Public interface (partition creation)
@@ -123,7 +125,7 @@ create_single_range_partition_internal(Oid parent_relid,
123125}
124126
125127/* check pathman config and fill variables */
126- expr = get_constraint_expression (parent_relid ,NULL ,& trigger_columns );
128+ expr = get_partitioning_expression (parent_relid ,NULL ,& trigger_columns );
127129
128130/* Create a partition & get 'partitioning expression' */
129131partition_relid = create_single_partition_internal (parent_relid ,
@@ -163,7 +165,7 @@ create_single_hash_partition_internal(Oid parent_relid,
163165char * tablespace )
164166{
165167Oid partition_relid ,
166- value_type ;
168+ expr_type ;
167169Constraint * check_constr ;
168170Node * expr ;
169171init_callback_params callback_params ;
@@ -187,14 +189,14 @@ create_single_hash_partition_internal(Oid parent_relid,
187189tablespace );
188190
189191/* check pathman config and fill variables */
190- expr = get_constraint_expression (parent_relid ,& value_type ,& trigger_columns );
192+ expr = get_partitioning_expression (parent_relid ,& expr_type ,& trigger_columns );
191193
192194/* Build check constraint for HASH partition */
193195check_constr = build_hash_check_constraint (partition_relid ,
194196expr ,
195197part_idx ,
196198part_count ,
197- value_type );
199+ expr_type );
198200
199201/* Cook args for init_callback */
200202MakeInitCallbackHashParams (& callback_params ,
@@ -1710,39 +1712,33 @@ validate_part_expression(Node *node, void *context)
17101712return expression_tree_walker (node ,validate_part_expression ,context );
17111713}
17121714
1713- /* Wraps expression by SELECT query and returnsparsed tree */
1715+ /* Wraps expression by SELECT query and returnsparse tree */
17141716Node *
1715- get_raw_expression (Oid relid ,const char * expr ,char * * query_string_out ,
1716- Node * * parsetree )
1717+ parse_partitioning_expression (Oid relid ,
1718+ const char * expression ,
1719+ char * * query_string_out ,
1720+ Node * * parsetree_out )
17171721{
1718- Node * result ;
1719- SelectStmt * select_stmt ;
1720- ResTarget * target ;
1722+ SelectStmt * select_stmt ;
1723+ List * parsetree_list ;
17211724
1722- char * fmt = "SELECT (%s) FROM ONLY %s.\"%s\"" ;
1723- char * relname = get_rel_name (relid ),
1724- * namespace_name = get_namespace_name (get_rel_namespace (relid ));
1725- List * parsetree_list ;
1726- char * query_string = psprintf (fmt ,expr ,namespace_name ,relname );
1725+ char * sql = "SELECT (%s) FROM ONLY %s.\"%s\"" ;
1726+ char * relname = get_rel_name (relid ),
1727+ * nspname = get_namespace_name (get_rel_namespace (relid ));
1728+ char * query_string = psprintf (sql ,expression ,nspname ,relname );
17271729
17281730parsetree_list = raw_parser (query_string );
17291731Assert (list_length (parsetree_list )== 1 );
17301732
1733+ select_stmt = (SelectStmt * )linitial (parsetree_list );
1734+
17311735if (query_string_out )
1732- {
17331736* query_string_out = query_string ;
1734- }
17351737
1736- select_stmt = (SelectStmt * )linitial (parsetree_list );
1738+ if (parsetree_out )
1739+ * parsetree_out = (Node * )select_stmt ;
17371740
1738- if (parsetree )
1739- {
1740- * parsetree = (Node * )select_stmt ;
1741- }
1742-
1743- target = (ResTarget * )linitial (select_stmt -> targetList );
1744- result = (Node * )target -> val ;
1745- return result ;
1741+ return ((ResTarget * )linitial (select_stmt -> targetList ))-> val ;
17461742}
17471743
17481744/*
@@ -1751,7 +1747,7 @@ get_raw_expression(Oid relid, const char *expr, char **query_string_out,
17511747 */
17521748PartExpressionInfo *
17531749get_part_expression_info (Oid relid ,const char * expr_string ,
1754- bool check_hash_func ,bool make_plan )
1750+ bool check_hash_func ,bool make_plan )
17551751{
17561752Node * expr_node ,
17571753* parsetree ;
@@ -1766,12 +1762,12 @@ get_part_expression_info(Oid relid, const char *expr_string,
17661762expr_info = palloc (sizeof (PartExpressionInfo ));
17671763
17681764pathman_parse_context = AllocSetContextCreate (TopPathmanContext ,
1769- "pathman parse context" ,
1770- ALLOCSET_DEFAULT_SIZES );
1765+ "pathman parse context" ,
1766+ ALLOCSET_DEFAULT_SIZES );
17711767
17721768/* Keep raw expression */
1773- expr_info -> raw_expr = get_raw_expression (relid ,expr_string ,
1774- & query_string ,& parsetree );
1769+ expr_info -> raw_expr = parse_partitioning_expression (relid ,expr_string ,
1770+ & query_string ,& parsetree );
17751771
17761772/* If expression is just column we check that is not null */
17771773if (IsA (expr_info -> raw_expr ,ColumnRef ))
@@ -1892,12 +1888,11 @@ extract_column_names(Node *node, struct extract_column_names_context *ctx)
18921888return raw_expression_tree_walker (node ,extract_column_names ,ctx );
18931889}
18941890
1895- /*
1896- * Returns raw partitioning expression, and if specified returns
1897- * columns from expression and its type
1898- */
1891+ /* Returns raw partitioning expression + expr_type + columns */
18991892static Node *
1900- get_constraint_expression (Oid parent_relid ,Oid * expr_type ,List * * columns )
1893+ get_partitioning_expression (Oid parent_relid ,
1894+ Oid * expr_type ,/* ret val #1 */
1895+ List * * columns )/* ret val #2 */
19011896{
19021897/* Values extracted from PATHMAN_CONFIG */
19031898Datum config_values [Natts_pathman_config ];
@@ -1906,28 +1901,24 @@ get_constraint_expression(Oid parent_relid, Oid *expr_type, List **columns)
19061901char * expr_string ;
19071902
19081903/* Check that table is registered in PATHMAN_CONFIG */
1909- if (!pathman_config_contains_relation (parent_relid ,
1910- config_values , config_nulls ,NULL ,NULL ))
1904+ if (!pathman_config_contains_relation (parent_relid ,config_values ,
1905+ config_nulls ,NULL ,NULL ))
19111906elog (ERROR ,"table \"%s\" is not partitioned" ,
19121907get_rel_name_or_relid (parent_relid ));
19131908
1914- /*
1915- * We need expression type for hash functions. Range functions don't need
1916- * this feature.
1917- */
1909+ /* We need expression type for hash functions */
19181910if (expr_type )
19191911* expr_type = DatumGetObjectId (config_values [Anum_pathman_config_atttype - 1 ]);
19201912
19211913expr_string = TextDatumGetCString (config_values [Anum_pathman_config_expression - 1 ]);
1922- expr = get_raw_expression (parent_relid ,expr_string ,NULL ,NULL );
1914+ expr = parse_partitioning_expression (parent_relid ,expr_string ,NULL ,NULL );
19231915pfree (expr_string );
19241916
19251917if (columns )
19261918{
1927- struct extract_column_names_context ctx ;
1928- ctx .columns = NIL ;
1929- extract_column_names (expr ,& ctx );
1930- * columns = ctx .columns ;
1919+ struct extract_column_names_context context = {NIL };
1920+ extract_column_names (expr ,& context );
1921+ * columns = context .columns ;
19311922}
19321923
19331924return expr ;