Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd44be0

Browse files
committed
Save expression in database
1 parent405c509 commitbd44be0

12 files changed

+259
-191
lines changed

‎hash.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
CREATEOR REPLACE FUNCTION @extschema@.create_hash_partitions(
1515
parent_relidREGCLASS,
16-
attributeTEXT,
16+
expressionTEXT,
1717
partitions_countINTEGER,
1818
partition_dataBOOLEAN DEFAULT TRUE,
1919
partition_namesTEXT[] DEFAULTNULL,
@@ -31,15 +31,15 @@ BEGIN
3131
PERFORM @extschema@.lock_partitioned_relation(parent_relid);
3232
END IF;
3333

34-
attribute :=lower(attribute);
35-
PERFORM @extschema@.common_relation_checks(parent_relid,attribute);
34+
expression :=lower(expression);
35+
PERFORM @extschema@.common_relation_checks(parent_relid,expression);
3636

3737
/* Insert new entry to pathman config*/
38-
PERFORM @extschema@.add_to_pathman_config(parent_relid,attribute);
38+
PERFORM @extschema@.add_to_pathman_config(parent_relid,expression,NULL, false);
3939

4040
/* Create partitions*/
4141
PERFORM @extschema@.create_hash_partitions_internal(parent_relid,
42-
attribute,
42+
expression,
4343
partitions_count,
4444
partition_names,
4545
tablespaces);

‎init.sql

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@ LANGUAGE C;
3535
CREATETABLEIF NOT EXISTS @extschema@.pathman_config (
3636
partrelREGCLASSNOT NULLPRIMARY KEY,
3737
attnameTEXTNOT NULL,
38+
raw_expressionTEXTNOT NULL,
3839
atttypeOIDNOT NULL,
3940
parttypeINTEGERNOT NULL,
4041
range_intervalTEXT,
4142

4243
/* check for allowed part types*/
43-
CHECK (parttypeIN (1,2)),
44+
CHECK (parttypeIN (1,2))
4445

4546
/* check for correct interval*/
47+
/*
4648
CHECK (@extschema@.validate_interval_value(partrel,
4749
attname,
4850
parttype,
49-
range_interval))
51+
range_interval))*/
5052
);
5153

5254

@@ -451,10 +453,6 @@ BEGIN
451453
RAISE EXCEPTION'relation "%" has already been partitioned', relation;
452454
END IF;
453455

454-
IF NOT @extschema@.is_expression_suitable(relation, expression) THEN
455-
RAISE EXCEPTION'partitioning expression "%" is not suitable', expression;
456-
END IF;
457-
458456
/* Check if there are foreign keys that reference the relation*/
459457
FOR v_recIN (SELECT*FROMpg_catalog.pg_constraint
460458
WHERE confrelid= relation::REGCLASS::OID)
@@ -800,11 +798,13 @@ LANGUAGE C STRICT;
800798
/*
801799
* Checks if expression is suitable
802800
*/
801+
/*
803802
CREATE OR REPLACE FUNCTION @extschema@.is_expression_suitable(
804803
relidREGCLASS,
805804
exprTEXT)
806805
RETURNS BOOLEAN AS 'pg_pathman', 'is_expression_suitable'
807806
LANGUAGE C STRICT;
807+
*/
808808

809809
/*
810810
* Check if regclass is date or timestamp.
@@ -848,9 +848,11 @@ LANGUAGE C STRICT;
848848
* Attach a previously partitioned table.
849849
*/
850850
CREATEOR REPLACE FUNCTION @extschema@.add_to_pathman_config(
851-
parent_relidREGCLASS,
852-
attnameTEXT,
853-
range_intervalTEXT DEFAULTNULL)
851+
parent_relidREGCLASS,
852+
attnameTEXT,
853+
range_intervalTEXT DEFAULTNULL,
854+
refresh_part_infoBOOL DEFAULT TRUE
855+
)
854856
RETURNSBOOLEANAS'pg_pathman','add_to_pathman_config'
855857
LANGUAGE C;
856858

‎src/include/partition_creation.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,25 @@ Oid create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type,
3232
Oidcreate_single_range_partition_internal(Oidparent_relid,
3333
constBound*start_value,
3434
constBound*end_value,
35-
Oidvalue_type,
3635
RangeVar*partition_rv,
3736
char*tablespace);
3837

3938
/* Create one HASH partition */
4039
Oidcreate_single_hash_partition_internal(Oidparent_relid,
4140
uint32part_idx,
4241
uint32part_count,
43-
Oidvalue_type,
4442
RangeVar*partition_rv,
4543
char*tablespace);
4644

4745

4846
/* RANGE constraints */
4947
Constraint*build_range_check_constraint(Oidchild_relid,
50-
char*attname,
48+
Node*raw_expression,
5149
constBound*start_value,
5250
constBound*end_value,
53-
Oidvalue_type);
51+
Oidexpr_type);
5452

55-
Node*build_raw_range_check_tree(char*attname,
53+
Node*build_raw_range_check_tree(Node*raw_expression,
5654
constBound*start_value,
5755
constBound*end_value,
5856
Oidvalue_type);
@@ -66,23 +64,29 @@ bool check_range_available(Oid parent_relid,
6664

6765
/* HASH constraints */
6866
Constraint*build_hash_check_constraint(Oidchild_relid,
69-
constchar*expr,
67+
Node*raw_expression,
7068
uint32part_idx,
7169
uint32part_count,
7270
Oidvalue_type);
7371

74-
Node*build_raw_hash_check_tree(constchar*base_expr,
72+
Node*build_raw_hash_check_tree(Node*raw_expression,
7573
uint32part_idx,
7674
uint32part_count,
7775
Oidrelid,
7876
Oidvalue_type);
7977

8078
voiddrop_check_constraint(Oidrelid,AttrNumberattnum);
8179

82-
/* expression parsing functions */
83-
Node*get_expression_node(Oidrelid,constchar*expr,boolanalyze);
84-
Oidget_partition_expr_type(Oidrelid,constchar*expr);
80+
typedefstruct
81+
{
82+
Oidexpr_type;
83+
Datumexpr_datum;
84+
Node*raw_expr;
85+
}PartExpressionInfo;
8586

87+
/* expression parsing functions */
88+
PartExpressionInfo*get_part_expression_info(Oidrelid,
89+
constchar*expr_string,boolcheck_hash_func,boolmake_plan);
8690

8791

8892
/* Partitioning callback type */

‎src/include/pathman.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@
4444
* Definitions for the "pathman_config" table.
4545
*/
4646
#definePATHMAN_CONFIG"pathman_config"
47-
#defineNatts_pathman_config5
47+
#defineNatts_pathman_config6
4848
#defineAnum_pathman_config_partrel1/* partitioned relation (regclass) */
49-
#defineAnum_pathman_config_attname2/* partitioned column (text) */
50-
#defineAnum_pathman_config_atttype3/* partitioned atttype */
51-
#defineAnum_pathman_config_parttype4/* partitioning type (1|2) */
52-
#defineAnum_pathman_config_range_interval5/* interval for RANGE pt. (text) */
49+
#defineAnum_pathman_config_expression2/* partitioned expression (text) */
50+
#defineAnum_pathman_config_raw_expression3/* partitioned raw expression (text) */
51+
#defineAnum_pathman_config_atttype4/* partitioned atttype */
52+
#defineAnum_pathman_config_parttype5/* partitioning type (1|2) */
53+
#defineAnum_pathman_config_range_interval6/* interval for RANGE pt. (text) */
5354

5455
/* type modifier (typmod) for 'range_interval' */
5556
#definePATHMAN_CONFIG_interval_typmod-1

‎src/include/relation_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ typedef struct
134134
Oid*children;/* Oids of child partitions */
135135
RangeEntry*ranges;/* per-partition range entry or NULL */
136136

137-
Expr*expr;/* planned expression */
137+
Node*expr;/* planned expression */
138138
PartTypeparttype;/* partitioning type (HASH | RANGE) */
139139
Oidatttype;/* expression type */
140140
int32atttypmod;/* expression type modifier */

‎src/init.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,8 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
711711

712712
/* Perform checks for non-NULL columns */
713713
Assert(!isnull[Anum_pathman_config_partrel-1]);
714-
Assert(!isnull[Anum_pathman_config_attname-1]);
714+
Assert(!isnull[Anum_pathman_config_expression-1]);
715+
Assert(!isnull[Anum_pathman_config_raw_expression-1]);
715716
Assert(!isnull[Anum_pathman_config_parttype-1]);
716717
}
717718

@@ -825,7 +826,8 @@ read_pathman_config(void)
825826
/* These attributes are marked as NOT NULL, check anyway */
826827
Assert(!isnull[Anum_pathman_config_partrel-1]);
827828
Assert(!isnull[Anum_pathman_config_parttype-1]);
828-
Assert(!isnull[Anum_pathman_config_attname-1]);
829+
Assert(!isnull[Anum_pathman_config_expression-1]);
830+
Assert(!isnull[Anum_pathman_config_raw_expression-1]);
829831

830832
/* Extract values from Datums */
831833
relid=DatumGetObjectId(values[Anum_pathman_config_partrel-1]);
@@ -1112,7 +1114,6 @@ validate_hash_constraint(const Expr *expr,
11121114
constOpExpr*eq_expr;
11131115
constFuncExpr*get_hash_expr,
11141116
*type_hash_proc_expr;
1115-
constVar*var;/* partitioned column */
11161117

11171118
if (!expr)
11181119
return false;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp