@@ -84,11 +84,13 @@ static void postprocess_child_table_and_atts(Oid parent_relid, Oid partition_rel
84
84
static Oid text_to_regprocedure (text * proname_args );
85
85
86
86
static Constraint * make_constraint_common (char * name ,Node * raw_expr );
87
- static Node * get_constraint_expression (Oid parent_relid ,
88
- Oid * expr_type ,List * * columns );
89
87
static Value make_string_value_struct (char * str );
90
88
static Value make_int_value_struct (int int_val );
91
89
90
+ static Node * get_partitioning_expression (Oid parent_relid ,
91
+ Oid * expr_type ,
92
+ List * * columns );
93
+
92
94
/*
93
95
* ---------------------------------------
94
96
* Public interface (partition creation)
@@ -123,7 +125,7 @@ create_single_range_partition_internal(Oid parent_relid,
123
125
}
124
126
125
127
/* 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 );
127
129
128
130
/* Create a partition & get 'partitioning expression' */
129
131
partition_relid = create_single_partition_internal (parent_relid ,
@@ -163,7 +165,7 @@ create_single_hash_partition_internal(Oid parent_relid,
163
165
char * tablespace )
164
166
{
165
167
Oid partition_relid ,
166
- value_type ;
168
+ expr_type ;
167
169
Constraint * check_constr ;
168
170
Node * expr ;
169
171
init_callback_params callback_params ;
@@ -187,14 +189,14 @@ create_single_hash_partition_internal(Oid parent_relid,
187
189
tablespace );
188
190
189
191
/* 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 );
191
193
192
194
/* Build check constraint for HASH partition */
193
195
check_constr = build_hash_check_constraint (partition_relid ,
194
196
expr ,
195
197
part_idx ,
196
198
part_count ,
197
- value_type );
199
+ expr_type );
198
200
199
201
/* Cook args for init_callback */
200
202
MakeInitCallbackHashParams (& callback_params ,
@@ -1710,39 +1712,33 @@ validate_part_expression(Node *node, void *context)
1710
1712
return expression_tree_walker (node ,validate_part_expression ,context );
1711
1713
}
1712
1714
1713
- /* Wraps expression by SELECT query and returnsparsed tree */
1715
+ /* Wraps expression by SELECT query and returnsparse tree */
1714
1716
Node *
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 )
1717
1721
{
1718
- Node * result ;
1719
- SelectStmt * select_stmt ;
1720
- ResTarget * target ;
1722
+ SelectStmt * select_stmt ;
1723
+ List * parsetree_list ;
1721
1724
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 );
1727
1729
1728
1730
parsetree_list = raw_parser (query_string );
1729
1731
Assert (list_length (parsetree_list )== 1 );
1730
1732
1733
+ select_stmt = (SelectStmt * )linitial (parsetree_list );
1734
+
1731
1735
if (query_string_out )
1732
- {
1733
1736
* query_string_out = query_string ;
1734
- }
1735
1737
1736
- select_stmt = (SelectStmt * )linitial (parsetree_list );
1738
+ if (parsetree_out )
1739
+ * parsetree_out = (Node * )select_stmt ;
1737
1740
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 ;
1746
1742
}
1747
1743
1748
1744
/*
@@ -1751,7 +1747,7 @@ get_raw_expression(Oid relid, const char *expr, char **query_string_out,
1751
1747
*/
1752
1748
PartExpressionInfo *
1753
1749
get_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 )
1755
1751
{
1756
1752
Node * expr_node ,
1757
1753
* parsetree ;
@@ -1766,12 +1762,12 @@ get_part_expression_info(Oid relid, const char *expr_string,
1766
1762
expr_info = palloc (sizeof (PartExpressionInfo ));
1767
1763
1768
1764
pathman_parse_context = AllocSetContextCreate (TopPathmanContext ,
1769
- "pathman parse context" ,
1770
- ALLOCSET_DEFAULT_SIZES );
1765
+ "pathman parse context" ,
1766
+ ALLOCSET_DEFAULT_SIZES );
1771
1767
1772
1768
/* 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 );
1775
1771
1776
1772
/* If expression is just column we check that is not null */
1777
1773
if (IsA (expr_info -> raw_expr ,ColumnRef ))
@@ -1892,12 +1888,11 @@ extract_column_names(Node *node, struct extract_column_names_context *ctx)
1892
1888
return raw_expression_tree_walker (node ,extract_column_names ,ctx );
1893
1889
}
1894
1890
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 */
1899
1892
static 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 */
1901
1896
{
1902
1897
/* Values extracted from PATHMAN_CONFIG */
1903
1898
Datum config_values [Natts_pathman_config ];
@@ -1906,28 +1901,24 @@ get_constraint_expression(Oid parent_relid, Oid *expr_type, List **columns)
1906
1901
char * expr_string ;
1907
1902
1908
1903
/* 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 ))
1911
1906
elog (ERROR ,"table \"%s\" is not partitioned" ,
1912
1907
get_rel_name_or_relid (parent_relid ));
1913
1908
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 */
1918
1910
if (expr_type )
1919
1911
* expr_type = DatumGetObjectId (config_values [Anum_pathman_config_atttype - 1 ]);
1920
1912
1921
1913
expr_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 );
1923
1915
pfree (expr_string );
1924
1916
1925
1917
if (columns )
1926
1918
{
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 ;
1931
1922
}
1932
1923
1933
1924
return expr ;