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

Commitffa33e7

Browse files
committed
WIP refactoring, move functions to reasonable files
1 parent11b1d5e commitffa33e7

17 files changed

+529
-564
lines changed

‎expected/pathman_calamity.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ ERROR: relation "0" does not exist
556556
SELECT add_to_pathman_config('calamity.part_test', NULL);/* no column */
557557
ERROR: 'expression' should not be NULL
558558
SELECT add_to_pathman_config('calamity.part_test', 'V_A_L');/* wrong column */
559-
ERROR:Cannot find type name for attribute "v_a_l" of relation "part_test"
559+
ERROR:cannot find type name for attribute "v_a_l" of relation "part_test"
560560
SELECT add_to_pathman_config('calamity.part_test', 'val');/* OK */
561561
add_to_pathman_config
562562
-----------------------

‎expected/pathman_utility_stmt.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ SELECT * FROM copy_stmt_hooking.test WHERE val > 20;
159159

160160
/* COPY FROM (partitioned column is not specified) */
161161
COPY copy_stmt_hooking.test(comment) FROM stdin;
162-
ERROR:partition expression's value should not be NULL
162+
ERROR:partitioning expression's value should not be NULL
163163
/* COPY FROM (we don't support FREEZE) */
164164
COPY copy_stmt_hooking.test FROM stdin WITH (FREEZE);
165165
ERROR: freeze is not supported for partitioned tables

‎src/hooks.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,10 @@ pathman_process_utility_hook(Node *parsetree,
800800
/* Override standard RENAME statement if needed */
801801
elseif (is_pathman_related_table_rename(parsetree,
802802
&relation_oid))
803+
{
803804
PathmanRenameConstraint(relation_oid,
804805
(constRenameStmt*)parsetree);
806+
}
805807

806808
/* Override standard ALTER COLUMN TYPE statement if needed */
807809
elseif (is_pathman_related_alter_column_type(parsetree,
@@ -810,15 +812,15 @@ pathman_process_utility_hook(Node *parsetree,
810812
&part_type))
811813
{
812814
if (part_type==PT_HASH)
813-
{
814815
ereport(ERROR,
815816
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
816817
errmsg("cannot change type of column \"%s\""
817818
" of table \"%s\" partitioned by HASH",
818819
get_attname(relation_oid,attr_number),
819820
get_rel_name(relation_oid))));
820-
}
821-
mark_pathman_expression_for_update(relation_oid);
821+
822+
/* Don't forget to invalidate parsed partitioning expression */
823+
pathman_config_invalidate_parsed_expression(relation_oid);
822824
}
823825
}
824826

‎src/include/init.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,15 @@ bool pathman_config_contains_relation(Oid relid,
204204
Datum*values,
205205
bool*isnull,
206206
TransactionId*xmin,
207-
HeapTuple*tuple);
207+
ItemPointerData*iptr);
208+
209+
voidpathman_config_invalidate_parsed_expression(Oidrelid);
210+
211+
voidpathman_config_refresh_parsed_expression(Oidrelid,
212+
Datum*values,
213+
bool*isnull,
214+
ItemPointeriptr);
215+
208216

209217
boolread_pathman_params(Oidrelid,
210218
Datum*values,

‎src/include/partition_creation.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,6 @@ Node * build_raw_hash_check_tree(Node *raw_expression,
7878

7979
voiddrop_check_constraint(Oidrelid);
8080

81-
typedefstruct
82-
{
83-
Oidexpr_type;
84-
Datumexpr_datum;
85-
Node*raw_expr;
86-
}PartExpressionInfo;
87-
88-
/* Expression parsing functions */
89-
PartExpressionInfo*get_part_expression_info(Oidrelid,
90-
constchar*expr_string,
91-
boolcheck_hash_func,
92-
boolmake_plan);
93-
94-
Node*parse_partitioning_expression(Oidrelid,
95-
constchar*expression,
96-
char**query_string_out,
97-
Node**parsetree_out);
9881

9982
/* Update triggers */
10083
voidcreate_single_update_trigger_internal(Oidpartition_relid,

‎src/include/partition_filter.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
#endif
2626

2727

28-
#defineERR_PART_ATTR_NULL"partition expression's value should not be NULL"
29-
#defineERR_PART_ATTR_MULTIPLE_RESULTS \
30-
"partition expression's value should be single, not set"
31-
#defineERR_PART_ATTR_NO_PART"no suitable partition for key '%s'"
32-
#defineERR_PART_ATTR_MULTIPLE"PartitionFilter selected more than one partition"
33-
#defineERR_PART_DESC_CONVERT"could not convert row type for partition"
28+
#defineERR_PART_ATTR_NULL"partitioning expression's value should not be NULL"
29+
#defineERR_PART_ATTR_MULTIPLE_RESULTS"partitioning expression should return single value"
30+
#defineERR_PART_ATTR_NO_PART"no suitable partition for key '%s'"
31+
#defineERR_PART_ATTR_MULTIPLE"PartitionFilter selected more than one partition"
32+
#defineERR_PART_DESC_CONVERT"could not convert row type for partition"
3433

3534

3635
/*

‎src/include/pathman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
#defineAnum_pathman_config_expression2/* partition expression (original) */
5050
#defineAnum_pathman_config_parttype3/* partitioning type (1|2) */
5151
#defineAnum_pathman_config_range_interval4/* interval for RANGE pt. (text) */
52-
#defineAnum_pathman_config_expression_p5/* parsedpartition expression (text) */
53-
#defineAnum_pathman_config_atttype6/* partitioned atttype */
52+
#defineAnum_pathman_config_expression_p5/* parsedpartitioning expression (text) */
53+
#defineAnum_pathman_config_atttype6/* partitioned atttype(oid)*/
5454

5555
/* type modifier (typmod) for 'range_interval' */
5656
#definePATHMAN_CONFIG_interval_typmod-1

‎src/include/relation_info.h

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include"postgres.h"
1616
#include"access/attnum.h"
17+
#include"access/sysattr.h"
1718
#include"fmgr.h"
1819
#include"nodes/bitmapset.h"
1920
#include"nodes/nodes.h"
@@ -86,7 +87,10 @@ FreeBound(Bound *bound, bool byval)
8687
}
8788

8889
inlinestaticint
89-
cmp_bounds(FmgrInfo*cmp_func,constOidcollid,constBound*b1,constBound*b2)
90+
cmp_bounds(FmgrInfo*cmp_func,
91+
constOidcollid,
92+
constBound*b1,
93+
constBound*b2)
9094
{
9195
if (IsMinusInfinity(b1)||IsPlusInfinity(b2))
9296
return-1;
@@ -139,10 +143,10 @@ typedef struct
139143
Oid*children;/* Oids of child partitions */
140144
RangeEntry*ranges;/* per-partition range entry or NULL */
141145

142-
constchar*attname;/* original expression */
146+
constchar*expr_cstr;/* original expression */
143147
Node*expr;/* planned expression */
144148
List*expr_vars;/* vars from expression, lazy */
145-
Bitmapset*expr_atts;/*set withattnums from expression */
149+
Bitmapset*expr_atts;/* attnums from expression */
146150

147151
Oidatttype;/* expression type */
148152
int32atttypmod;/* expression type modifier */
@@ -155,6 +159,8 @@ typedef struct
155159
hash_proc;/* hash function for 'atttype' */
156160
}PartRelationInfo;
157161

162+
#definePART_EXPR_VARNO( 1 )
163+
158164
/*
159165
* PartParentInfo
160166
*Cached parent of the specified partition.
@@ -166,18 +172,6 @@ typedef struct
166172
Oidparent_rel;
167173
}PartParentInfo;
168174

169-
/*
170-
* CustomConst
171-
*Modified Const that also stores 'varattno' attribute from some Var
172-
*We can check that is CustomConst by checking `location` attrubute.
173-
*It should be equal -2
174-
*/
175-
typedefstruct
176-
{
177-
Constcns;
178-
AttrNumbervarattno;
179-
}CustomConst;
180-
181175
/*
182176
* PartBoundInfo
183177
*Cached bounds of the specified partition.
@@ -242,11 +236,13 @@ static inline List *
242236
PrelExpressionColumnNames(constPartRelationInfo*prel)
243237
{
244238
List*columns=NIL;
245-
intj=-1;
239+
inti=-1;
246240

247-
while ((j=bms_next_member(prel->expr_atts,j)) >=0)
241+
while ((i=bms_next_member(prel->expr_atts,i)) >=0)
248242
{
249-
char*attname=get_attname(prel->key,j);
243+
AttrNumberattnum=i+FirstLowInvalidHeapAttributeNumber;
244+
char*attname=get_attname(PrelParentRelid(prel),attnum);
245+
250246
columns=lappend(columns,makeString(attname));
251247
}
252248

@@ -257,15 +253,22 @@ PrelExpressionColumnNames(const PartRelationInfo *prel)
257253
constPartRelationInfo*refresh_pathman_relation_info(Oidrelid,
258254
Datum*values,
259255
boolallow_incomplete);
260-
PartRelationInfo*invalidate_pathman_relation_info(Oidrelid,bool*found);
256+
PartRelationInfo*invalidate_pathman_relation_info(Oidrelid,bool*found);
261257
voidremove_pathman_relation_info(Oidrelid);
262258
constPartRelationInfo*get_pathman_relation_info(Oidrelid);
263259
constPartRelationInfo*get_pathman_relation_info_after_lock(Oidrelid,
264260
boolunlock_if_not_found,
265261
LockAcquireResult*lock_result);
266262

267-
/* Expression related routines */
268-
voidmark_pathman_expression_for_update(Oidrelid);
263+
/* Partitioning expression routines */
264+
Node*parse_partitioning_expression(constOidrelid,
265+
constchar*expression,
266+
char**query_string_out,
267+
Node**parsetree_out);
268+
269+
Datumplan_partitioning_expression(constOidrelid,
270+
constchar*expr_cstr,
271+
Oid*expr_type);
269272

270273
/* Global invalidation routines */
271274
voiddelay_pathman_shutdown(void);
@@ -280,12 +283,12 @@ Oid get_parent_of_partition(Oid partition, PartParentSearch *status);
280283

281284
/* Bounds cache */
282285
voidforget_bounds_of_partition(Oidpartition);
283-
PartBoundInfo*get_bounds_of_partition(Oidpartition,
284-
constPartRelationInfo*prel);
286+
PartBoundInfo*get_bounds_of_partition(Oidpartition,
287+
constPartRelationInfo*prel);
285288

286289
/* Safe casts for PartType */
287290
PartTypeDatumGetPartType(Datumdatum);
288-
char*PartTypeToCString(PartTypeparttype);
291+
char*PartTypeToCString(PartTypeparttype);
289292

290293
/* PartRelationInfo checker */
291294
voidshout_if_prel_is_invalid(constOidparent_oid,
@@ -367,5 +370,6 @@ extern bool pg_pathman_enable_bounds_cache;
367370

368371
voidinit_relation_info_static_data(void);
369372

373+
370374
#endif/* RELATION_INFO_H */
371375

‎src/include/utils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,5 @@ Datum extract_binary_interval_from_text(Datum interval_text,
6565
char**deconstruct_text_array(Datumarray,int*array_size);
6666
RangeVar**qualified_relnames_to_rangevars(char**relnames,size_tnrelnames);
6767

68-
AttrNumber*get_pathman_attributes_map(constPartRelationInfo*prel,
69-
Relationchild);
7068

7169
#endif/* PATHMAN_UTILS_H */

‎src/init.c

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,11 @@ build_update_trigger_func_name_internal(Oid relid)
599599

600600
/*
601601
* Check that relation 'relid' is partitioned by pg_pathman.
602-
*
603-
* Extract tuple into 'values' and 'isnull' if they're provided.
602+
* Extract tuple into 'values', 'isnull', 'xmin', 'iptr' if they're provided.
604603
*/
605604
bool
606605
pathman_config_contains_relation(Oidrelid,Datum*values,bool*isnull,
607-
TransactionId*xmin,HeapTuple*tuple)
606+
TransactionId*xmin,ItemPointerData*iptr)
608607
{
609608
Relationrel;
610609
HeapScanDescscan;
@@ -662,8 +661,9 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
662661
*xmin=DatumGetTransactionId(value);
663662
}
664663

665-
if (tuple)
666-
*tuple=heap_copytuple(htup);
664+
/* Set ItemPointer if necessary */
665+
if (iptr)
666+
*iptr=htup->t_self;
667667
}
668668

669669
/* Clean resources */
@@ -677,9 +677,78 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
677677
returncontains_rel;
678678
}
679679

680+
/* Invalidate parsed partitioning expression in PATHMAN_CONFIG */
681+
void
682+
pathman_config_invalidate_parsed_expression(Oidrelid)
683+
{
684+
ItemPointerDataiptr;/* pointer to tuple */
685+
Datumvalues[Natts_pathman_config];
686+
boolnulls[Natts_pathman_config];
687+
688+
/* Check that PATHMAN_CONFIG table contains this relation */
689+
if (pathman_config_contains_relation(relid,values,nulls,NULL,&iptr))
690+
{
691+
Relationrel;
692+
HeapTuplenew_htup;
693+
694+
/* Reset parsed expression */
695+
values[Anum_pathman_config_expression_p-1]= (Datum)0;
696+
nulls[Anum_pathman_config_expression_p-1]= true;
697+
698+
/* Reset expression type */
699+
values[Anum_pathman_config_atttype-1]= (Datum)0;
700+
nulls[Anum_pathman_config_atttype-1]= true;
701+
702+
rel=heap_open(get_pathman_config_relid(false),RowExclusiveLock);
703+
704+
/* Form new tuple and perform an update */
705+
new_htup=heap_form_tuple(RelationGetDescr(rel),values,nulls);
706+
simple_heap_update(rel,&iptr,new_htup);
707+
CatalogUpdateIndexes(rel,new_htup);
708+
709+
heap_close(rel,RowExclusiveLock);
710+
}
711+
}
712+
713+
/* Refresh parsed partitioning expression in PATHMAN_CONFIG */
714+
void
715+
pathman_config_refresh_parsed_expression(Oidrelid,
716+
Datum*values,
717+
bool*isnull,
718+
ItemPointeriptr)
719+
{
720+
char*expr_cstr;
721+
Oidexpr_type;
722+
Datumexpr_datum;
723+
724+
Relationrel;
725+
HeapTuplehtup_new;
726+
727+
/* get and parse expression */
728+
expr_cstr=TextDatumGetCString(values[Anum_pathman_config_expression-1]);
729+
expr_datum=plan_partitioning_expression(relid,expr_cstr,&expr_type);
730+
pfree(expr_cstr);
731+
732+
/* prepare tuple values */
733+
values[Anum_pathman_config_expression_p-1]=expr_datum;
734+
isnull[Anum_pathman_config_expression_p-1]= false;
735+
736+
values[Anum_pathman_config_atttype-1]=ObjectIdGetDatum(expr_type);
737+
isnull[Anum_pathman_config_atttype-1]= false;
738+
739+
rel=heap_open(get_pathman_config_relid(false),RowExclusiveLock);
740+
741+
htup_new=heap_form_tuple(RelationGetDescr(rel),values,isnull);
742+
simple_heap_update(rel,iptr,htup_new);
743+
CatalogUpdateIndexes(rel,htup_new);
744+
745+
heap_close(rel,RowExclusiveLock);
746+
}
747+
748+
680749
/*
681-
* Loads additional pathman parameters like 'enable_parent' or 'auto'
682-
* from PATHMAN_CONFIG_PARAMS.
750+
* Loads additional pathman parameters like 'enable_parent'
751+
*or 'auto'from PATHMAN_CONFIG_PARAMS.
683752
*/
684753
bool
685754
read_pathman_params(Oidrelid,Datum*values,bool*isnull)
@@ -722,6 +791,7 @@ read_pathman_params(Oid relid, Datum *values, bool *isnull)
722791
returnrow_found;
723792
}
724793

794+
725795
/*
726796
* Go through the PATHMAN_CONFIG table and create PartRelationInfo entries.
727797
*/
@@ -788,10 +858,9 @@ read_pathman_config(void)
788858

789859
/*
790860
* Validates range constraint. It MUST have one of the following formats:
791-
*
792-
*EXPRESSION >= CONST AND EXPRESSION < CONST
793-
*EXPRESSION >= CONST
794-
*EXPRESSION < CONST
861+
*1) EXPRESSION >= CONST AND EXPRESSION < CONST
862+
*2) EXPRESSION >= CONST
863+
*3) EXPRESSION < CONST
795864
*
796865
* Writes 'lower' & 'upper' and 'lower_null' & 'upper_null' values on success.
797866
*/
@@ -838,7 +907,11 @@ validate_range_constraint(const Expr *expr,
838907
lower,upper,lower_null,upper_null);
839908
}
840909

841-
/* Validates a single expression of kind EXPRESSION >= CONST | EXPRESSION < CONST */
910+
/*
911+
* Validates a single expression of kind:
912+
*1) EXPRESSION >= CONST
913+
*2) EXPRESSION < CONST
914+
*/
842915
staticbool
843916
validate_range_opexpr(constExpr*expr,
844917
constPartRelationInfo*prel,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp