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

Commit5764bb3

Browse files
committed
pathman: cleanups
1 parent24c39fd commit5764bb3

File tree

5 files changed

+223
-257
lines changed

5 files changed

+223
-257
lines changed

‎contrib/pathman/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# contrib/pathman/Makefile
22

33
MODULE_big = pathman
4-
OBJS = init.o pathman.o dsm_array.o rangeset.o$(WIN32RES)
4+
OBJS = init.o pathman.o dsm_array.o rangeset.opl_funcs.o$(WIN32RES)
55

66
EXTENSION = pathman
77
EXTVERSION = 0.1

‎contrib/pathman/README.rus.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ CHECK ( id >= 200 AND id < 300 )
2929
```
3030
WHERE id = 150
3131
```
32+
Затем основываясь на стратегии секционирования и условиях запроса`pathman` выбирает соответствующие секции и строит план.
3233

3334
##Installation
3435

‎contrib/pathman/pathman.c

Lines changed: 14 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ typedef struct
4141
/* Original hooks */
4242
staticset_rel_pathlist_hook_typeset_rel_pathlist_hook_original=NULL;
4343
staticshmem_startup_hook_typeshmem_startup_hook_original=NULL;
44+
staticplanner_hook_typeplanner_hook_original=NULL;
4445

4546
void_PG_init(void);
4647
void_PG_fini(void);
4748
staticvoidpathman_shmem_startup(void);
48-
staticvoidmy_hook(PlannerInfo*root,RelOptInfo*rel,Indexrti,RangeTblEntry*rte);
49-
staticPlannedStmt*my_planner_hook(Query*parse,intcursorOptions,ParamListInfoboundParams);
49+
staticvoidpathman_set_rel_pathlist_hook(PlannerInfo*root,RelOptInfo*rel,Indexrti,RangeTblEntry*rte);
50+
staticPlannedStmt*pathman_planner_hook(Query*parse,intcursorOptions,ParamListInfoboundParams);
5051

5152
staticvoidappend_child_relation(PlannerInfo*root,RelOptInfo*rel,Indexrti,
5253
RangeTblEntry*rte,intindex,OidchildOID,List*wrappers);
@@ -57,7 +58,6 @@ bool inheritance_disabled;
5758

5859
staticWrapperNode*walk_expr_tree(Expr*expr,constPartRelationInfo*prel);
5960
staticintmake_hash(constPartRelationInfo*prel,intvalue);
60-
staticintrange_binary_search(constRangeRelation*rangerel,FmgrInfo*cmp_func,Datumvalue,bool*fountPtr);
6161
staticvoidhandle_binary_opexpr(constPartRelationInfo*prel,WrapperNode*result,constVar*v,constConst*c);
6262
staticWrapperNode*handle_opexpr(constOpExpr*expr,constPartRelationInfo*prel);
6363
staticWrapperNode*handle_boolexpr(constBoolExpr*expr,constPartRelationInfo*prel);
@@ -71,14 +71,6 @@ static void change_varnos_in_restrinct_info(RestrictInfo *rinfo, change_varno_co
7171
staticvoidchange_varnos(Node*node,Oidold_varno,Oidnew_varno);
7272
staticboolchange_varno_walker(Node*node,change_varno_context*context);
7373

74-
/* callbacks */
75-
PG_FUNCTION_INFO_V1(on_partitions_created );
76-
PG_FUNCTION_INFO_V1(on_partitions_updated );
77-
PG_FUNCTION_INFO_V1(on_partitions_removed );
78-
PG_FUNCTION_INFO_V1(find_range_partition );
79-
PG_FUNCTION_INFO_V1(get_range_by_idx );
80-
PG_FUNCTION_INFO_V1(get_partition_range );
81-
8274

8375
/*
8476
* Compare two Datums with the given comarison function
@@ -105,11 +97,11 @@ void
10597
_PG_init(void)
10698
{
10799
set_rel_pathlist_hook_original=set_rel_pathlist_hook;
108-
set_rel_pathlist_hook=my_hook;
100+
set_rel_pathlist_hook=pathman_set_rel_pathlist_hook;
109101
shmem_startup_hook_original=shmem_startup_hook;
110102
shmem_startup_hook=pathman_shmem_startup;
111-
112-
planner_hook=my_planner_hook;
103+
planner_hook_original=planner_hook;
104+
planner_hook=pathman_planner_hook;
113105
}
114106

115107
void
@@ -121,7 +113,7 @@ _PG_fini(void)
121113

122114
/* TODO: rename and write a descritption */
123115
PlannedStmt*
124-
my_planner_hook(Query*parse,intcursorOptions,ParamListInfoboundParams)
116+
pathman_planner_hook(Query*parse,intcursorOptions,ParamListInfoboundParams)
125117
{
126118
PlannedStmt*result;
127119

@@ -138,7 +130,8 @@ my_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
138130
}
139131

140132
/*
141-
*
133+
* Disables inheritance for partitioned by pathman relations. It must be done to
134+
* prevent PostgresSQL from full search.
142135
*/
143136
staticvoid
144137
disable_inheritance(Query*parse)
@@ -213,7 +206,7 @@ pathman_shmem_startup(void)
213206
* The hook function. All the magic goes here
214207
*/
215208
void
216-
my_hook(PlannerInfo*root,RelOptInfo*rel,Indexrti,RangeTblEntry*rte)
209+
pathman_set_rel_pathlist_hook(PlannerInfo*root,RelOptInfo*rel,Indexrti,RangeTblEntry*rte)
217210
{
218211
PartRelationInfo*prel=NULL;
219212

@@ -788,7 +781,7 @@ make_hash(const PartRelationInfo *prel, int value)
788781
* If item wasn't found then function returns closest position and sets
789782
* foundPtr to false.
790783
*/
791-
staticint
784+
int
792785
range_binary_search(constRangeRelation*rangerel,FmgrInfo*cmp_func,Datumvalue,bool*foundPtr)
793786
{
794787
RangeEntry*ranges=dsm_array_get_pointer(&rangerel->ranges);
@@ -968,7 +961,9 @@ handle_arrexpr(const ScalarArrayOpExpr *expr, const PartRelationInfo *prel)
968961
returnresult;
969962
}
970963

971-
/* copy-past from allpaths.c with modifications */
964+
/*
965+
* Copy-paste functions from allpaths.c with (or without) some modifications
966+
*/
972967

973968
/*
974969
* set_plain_rel_pathlist
@@ -1132,198 +1127,3 @@ accumulate_append_subpath(List *subpaths, Path *path)
11321127
{
11331128
returnlappend(subpaths,path);
11341129
}
1135-
1136-
1137-
/*
1138-
* Callbacks
1139-
*/
1140-
Datum
1141-
on_partitions_created(PG_FUNCTION_ARGS)
1142-
{
1143-
// Oid relid;
1144-
1145-
LWLockAcquire(load_config_lock,LW_EXCLUSIVE);
1146-
1147-
/* Reload config */
1148-
/* TODO: reload just the specified relation */
1149-
// relid = DatumGetInt32(PG_GETARG_DATUM(0))
1150-
load_part_relations_hashtable(false);
1151-
1152-
LWLockRelease(load_config_lock);
1153-
1154-
PG_RETURN_NULL();
1155-
}
1156-
1157-
Datum
1158-
on_partitions_updated(PG_FUNCTION_ARGS)
1159-
{
1160-
Oidrelid;
1161-
PartRelationInfo*prel;
1162-
1163-
/* parent relation oid */
1164-
relid=DatumGetInt32(PG_GETARG_DATUM(0));
1165-
prel= (PartRelationInfo*)
1166-
hash_search(relations, (constvoid*)&relid,HASH_FIND,0);
1167-
if (prel!=NULL)
1168-
{
1169-
LWLockAcquire(load_config_lock,LW_EXCLUSIVE);
1170-
remove_relation_info(relid);
1171-
load_part_relations_hashtable(false);
1172-
LWLockRelease(load_config_lock);
1173-
}
1174-
1175-
PG_RETURN_NULL();
1176-
}
1177-
1178-
Datum
1179-
on_partitions_removed(PG_FUNCTION_ARGS)
1180-
{
1181-
Oidrelid;
1182-
1183-
LWLockAcquire(load_config_lock,LW_EXCLUSIVE);
1184-
1185-
/* parent relation oid */
1186-
relid=DatumGetInt32(PG_GETARG_DATUM(0));
1187-
remove_relation_info(relid);
1188-
1189-
LWLockRelease(load_config_lock);
1190-
1191-
PG_RETURN_NULL();
1192-
}
1193-
1194-
/*
1195-
* Returns partition oid for specified parent relid and value
1196-
*/
1197-
Datum
1198-
find_range_partition(PG_FUNCTION_ARGS)
1199-
{
1200-
intrelid=DatumGetInt32(PG_GETARG_DATUM(0));
1201-
Datumvalue=PG_GETARG_DATUM(1);
1202-
Oidvalue_type=get_fn_expr_argtype(fcinfo->flinfo,1);
1203-
intpos;
1204-
boolfound;
1205-
RangeRelation*rangerel;
1206-
RangeEntry*ranges;
1207-
TypeCacheEntry*tce;
1208-
FmgrInfo*cmp_func;
1209-
1210-
tce=lookup_type_cache(value_type,
1211-
TYPECACHE_EQ_OPR |TYPECACHE_LT_OPR |TYPECACHE_GT_OPR |
1212-
TYPECACHE_CMP_PROC |TYPECACHE_CMP_PROC_FINFO);
1213-
cmp_func=&tce->cmp_proc_finfo;
1214-
1215-
rangerel= (RangeRelation*)
1216-
hash_search(range_restrictions, (constvoid*)&relid,HASH_FIND,NULL);
1217-
1218-
if (!rangerel)
1219-
PG_RETURN_NULL();
1220-
1221-
ranges=dsm_array_get_pointer(&rangerel->ranges);
1222-
pos=range_binary_search(rangerel,cmp_func,value,&found);
1223-
1224-
if (found)
1225-
PG_RETURN_OID(ranges[pos].child_oid);
1226-
1227-
PG_RETURN_NULL();
1228-
}
1229-
1230-
/*
1231-
* Returns range (min, max) as output parameters
1232-
*
1233-
* first argument is the parent relid
1234-
* second is the partition relid
1235-
* third and forth are MIN and MAX output parameters
1236-
*/
1237-
Datum
1238-
get_partition_range(PG_FUNCTION_ARGS)
1239-
{
1240-
intparent_oid=DatumGetInt32(PG_GETARG_DATUM(0));
1241-
intchild_oid=DatumGetInt32(PG_GETARG_DATUM(1));
1242-
intnelems=2;
1243-
inti;
1244-
boolfound= false;
1245-
Datum*elems;
1246-
PartRelationInfo*prel;
1247-
RangeRelation*rangerel;
1248-
RangeEntry*ranges;
1249-
TypeCacheEntry*tce;
1250-
ArrayType*arr;
1251-
1252-
prel= (PartRelationInfo*)
1253-
hash_search(relations, (constvoid*)&parent_oid,HASH_FIND,NULL);
1254-
1255-
rangerel= (RangeRelation*)
1256-
hash_search(range_restrictions, (constvoid*)&parent_oid,HASH_FIND,NULL);
1257-
1258-
if (!prel|| !rangerel)
1259-
PG_RETURN_NULL();
1260-
1261-
ranges=dsm_array_get_pointer(&rangerel->ranges);
1262-
tce=lookup_type_cache(prel->atttype,0);
1263-
1264-
/* looking for specified partition */
1265-
for(i=0;i<rangerel->ranges.length;i++)
1266-
if (ranges[i].child_oid==child_oid)
1267-
{
1268-
found= true;
1269-
break;
1270-
}
1271-
1272-
if (found)
1273-
{
1274-
elems=palloc(nelems*sizeof(Datum));
1275-
elems[0]=ranges[i].min;
1276-
elems[1]=ranges[i].max;
1277-
1278-
arr=construct_array(elems,nelems,prel->atttype,
1279-
tce->typlen,tce->typbyval,tce->typalign);
1280-
PG_RETURN_ARRAYTYPE_P(arr);
1281-
}
1282-
1283-
PG_RETURN_NULL();
1284-
}
1285-
1286-
1287-
/*
1288-
* Returns N-th range (in form of array)
1289-
*
1290-
* First argument is the parent relid.
1291-
* Second argument is the index of the range (if it is negative then the last
1292-
* range will be returned).
1293-
*/
1294-
Datum
1295-
get_range_by_idx(PG_FUNCTION_ARGS)
1296-
{
1297-
intparent_oid=DatumGetInt32(PG_GETARG_DATUM(0));
1298-
intidx=DatumGetInt32(PG_GETARG_DATUM(1));
1299-
PartRelationInfo*prel;
1300-
RangeRelation*rangerel;
1301-
RangeEntry*ranges;
1302-
RangeEntry*re;
1303-
Datum*elems;
1304-
TypeCacheEntry*tce;
1305-
1306-
prel= (PartRelationInfo*)
1307-
hash_search(relations, (constvoid*)&parent_oid,HASH_FIND,NULL);
1308-
1309-
rangerel= (RangeRelation*)
1310-
hash_search(range_restrictions, (constvoid*)&parent_oid,HASH_FIND,NULL);
1311-
1312-
if (!prel|| !rangerel||idx >= (int)rangerel->ranges.length)
1313-
PG_RETURN_NULL();
1314-
1315-
tce=lookup_type_cache(prel->atttype,0);
1316-
ranges=dsm_array_get_pointer(&rangerel->ranges);
1317-
if (idx >=0)
1318-
re=&ranges[idx];
1319-
else
1320-
re=&ranges[rangerel->ranges.length-1];
1321-
1322-
elems=palloc(2*sizeof(Datum));
1323-
elems[0]=re->min;
1324-
elems[1]=re->max;
1325-
1326-
PG_RETURN_ARRAYTYPE_P(
1327-
construct_array(elems,2,prel->atttype,
1328-
tce->typlen,tce->typbyval,tce->typalign));
1329-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp