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

Commit94e8576

Browse files
committed
pathman: 32bit systems issue fix (not finished)
1 parentcabfa87 commit94e8576

File tree

3 files changed

+80
-15
lines changed

3 files changed

+80
-15
lines changed

‎contrib/pg_pathman/init.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
HTAB*relations=NULL;
1818
HTAB*range_restrictions=NULL;
19-
// bool *config_loaded = NULL;
2019
boolinitialization_needed= true;
2120

2221
typedefstructShmemConfig
@@ -26,6 +25,7 @@ typedef struct ShmemConfig
2625
ShmemConfig*shmem_cfg;
2726

2827
staticFmgrInfo*qsort_type_cmp_func;
28+
staticboolglobalByVal;
2929

3030
staticboolvalidate_range_constraint(Expr*,PartRelationInfo*,Datum*,Datum*);
3131
staticboolvalidate_hash_constraint(Expr*expr,PartRelationInfo*prel,int*hash);
@@ -247,6 +247,7 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
247247

248248
if (prel->parttype==PT_RANGE)
249249
{
250+
TypeCacheEntry*tce;
250251
RelationKeykey;
251252
key.dbid=MyDatabaseId;
252253
key.relid=parent_oid;
@@ -256,6 +257,9 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
256257

257258
alloc_dsm_array(&rangerel->ranges,sizeof(RangeEntry),proc);
258259
ranges= (RangeEntry*)dsm_array_get_pointer(&rangerel->ranges);
260+
261+
tce=lookup_type_cache(prel->atttype,0);
262+
rangerel->by_val=tce->typbyval;
259263
}
260264

261265
for (i=0;i<proc;i++)
@@ -290,10 +294,19 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
290294
continue;
291295
}
292296

297+
/* If datum is referenced by val then just assign */
298+
if (rangerel->by_val)
299+
{
300+
re.min=min;
301+
re.max=max;
302+
}
303+
/* else copy the memory by pointer */
304+
else
305+
{
306+
memcpy(&re.min,DatumGetPointer(min),sizeof(re.min));
307+
memcpy(&re.max,DatumGetPointer(max),sizeof(re.max));
308+
}
293309
re.child_oid=con->conrelid;
294-
re.min=min;
295-
re.max=max;
296-
297310
ranges[i]=re;
298311
break;
299312

@@ -313,11 +326,13 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
313326
if (prel->parttype==PT_RANGE)
314327
{
315328
TypeCacheEntry*tce;
329+
boolbyVal=rangerel->by_val;
316330

317331
/* Sort ascending */
318332
tce=lookup_type_cache(prel->atttype,
319333
TYPECACHE_CMP_PROC |TYPECACHE_CMP_PROC_FINFO);
320334
qsort_type_cmp_func=&tce->cmp_proc_finfo;
335+
globalByVal=byVal;
321336
qsort(ranges,proc,sizeof(RangeEntry),cmp_range_entries);
322337

323338
/* Copy oids to prel */
@@ -327,6 +342,10 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
327342
/* Check if some ranges overlap */
328343
for(i=0;i<proc-1;i++)
329344
{
345+
Datummin=PATHMAN_GET_DATUM(ranges[i].max,byVal);
346+
Datummax=PATHMAN_GET_DATUM(ranges[i+1].min,byVal);
347+
348+
// if (FunctionCall2(qsort_type_cmp_func, min, max) > 0)
330349
if (ranges[i].max>ranges[i+1].min)
331350
{
332351
RelationKeykey;
@@ -350,7 +369,10 @@ cmp_range_entries(const void *p1, const void *p2)
350369
constRangeEntry*v1= (constRangeEntry*)p1;
351370
constRangeEntry*v2= (constRangeEntry*)p2;
352371

353-
returnFunctionCall2(qsort_type_cmp_func,v1->min,v2->min);
372+
// return FunctionCall2(qsort_type_cmp_func, v1->min, v2->min);
373+
returnFunctionCall2(qsort_type_cmp_func,
374+
PATHMAN_GET_DATUM(v1->min,globalByVal),
375+
PATHMAN_GET_DATUM(v2->min,globalByVal));
354376
}
355377

356378
/*

‎contrib/pg_pathman/pathman.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,25 @@ typedef struct HashRelation
8282
typedefstructRangeEntry
8383
{
8484
Oidchild_oid;
85-
Datummin;
86-
Datummax;
85+
// Datummin;
86+
// Datummax;
87+
#ifdefHAVE_INT64_TIMESTAMP
88+
int64min;
89+
int64max;
90+
#else
91+
doublemin;
92+
doublemax;
93+
#endif
8794
}RangeEntry;
8895

8996
typedefstructRangeRelation
9097
{
9198
RelationKeykey;
99+
boolby_val;
92100
DsmArrayranges;
93101
}RangeRelation;
94102

103+
#definePATHMAN_GET_DATUM(value,by_val) ( (by_val) ? (value) : PointerGetDatum(&value) )
95104

96105
typedefintIndexRange;
97106
#defineRANGE_INFINITY 0x7FFF
@@ -163,5 +172,7 @@ char *get_extension_schema(void);
163172
FmgrInfo*get_cmp_func(Oidtype1,Oidtype2);
164173
Oidcreate_partitions_bg_worker(Oidrelid,Datumvalue,Oidvalue_type);
165174
Oidcreate_partitions(Oidrelid,Datumvalue,Oidvalue_type);
175+
// Datum get_range_min(range, size_t idx, bool byVal);
176+
// Datum get_range_max(range, size_t idx, bool byVal);
166177

167178
#endif/* PATHMAN_H */

‎contrib/pg_pathman/pg_pathman.c

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,24 @@ get_cmp_func(Oid type1, Oid type2)
166166
returncmp_func;
167167
}
168168

169+
// Datums
170+
// get_range_min(range, size_t idx, bool byVal)
171+
// {
172+
// if (byVal)
173+
// return (Datum)range[idx].min;
174+
// else
175+
// return PointerGetDatum(&range[idx].min);
176+
// }
177+
178+
// Datum
179+
// get_range_max(range, size_t idx, bool byVal)
180+
// {
181+
// if (byVal)
182+
// return (Datum)range[idx].max;
183+
// else
184+
// return PointerGetDatum(&range[idx].max);
185+
// }
186+
169187
/*
170188
* Planner hook. It disables inheritance for tables that have been partitioned
171189
* by pathman to prevent standart PostgreSQL partitioning mechanism from
@@ -702,6 +720,7 @@ handle_binary_opexpr(const PartRelationInfo *prel, WrapperNode *result,
702720
cmp_max,
703721
endidx=rangerel->ranges.length-1;
704722
RangeEntry*ranges=dsm_array_get_pointer(&rangerel->ranges);
723+
boolbyVal=rangerel->by_val;
705724

706725
/* Check boundaries */
707726
if (rangerel->ranges.length==0)
@@ -712,8 +731,12 @@ handle_binary_opexpr(const PartRelationInfo *prel, WrapperNode *result,
712731
else
713732
{
714733
/* Corner cases */
715-
cmp_min=FunctionCall2(&cmp_func,value,ranges[0].min),
716-
cmp_max=FunctionCall2(&cmp_func,value,ranges[rangerel->ranges.length-1].max);
734+
// cmp_min = FunctionCall2(&cmp_func, value, ranges[0].min),
735+
// cmp_max = FunctionCall2(&cmp_func, value, ranges[rangerel->ranges.length - 1].max);
736+
cmp_min=FunctionCall2(&cmp_func,value,
737+
PATHMAN_GET_DATUM(ranges[0].min,byVal)),
738+
cmp_max=FunctionCall2(&cmp_func,value,
739+
PATHMAN_GET_DATUM(ranges[rangerel->ranges.length-1].max,byVal));
717740

718741
if ((cmp_min<0&&
719742
(strategy==BTLessEqualStrategyNumber||
@@ -753,8 +776,11 @@ handle_binary_opexpr(const PartRelationInfo *prel, WrapperNode *result,
753776
i=startidx+ (endidx-startidx) /2;
754777
Assert(i >=0&&i<rangerel->ranges.length);
755778
re=&ranges[i];
756-
cmp_min=FunctionCall2(&cmp_func,value,re->min);
757-
cmp_max=FunctionCall2(&cmp_func,value,re->max);
779+
// cmp_min = FunctionCall2(&cmp_func, value, re->min);
780+
// cmp_max = FunctionCall2(&cmp_func, value, re->max);
781+
cmp_min=FunctionCall2(&cmp_func,value,PATHMAN_GET_DATUM(re->min,byVal));
782+
cmp_max=FunctionCall2(&cmp_func,value,PATHMAN_GET_DATUM(re->max,byVal));
783+
758784
is_less= (cmp_min<0|| (cmp_min==0&&strategy==BTLessStrategyNumber));
759785
is_greater= (cmp_max>0|| (cmp_max >=0&&strategy!=BTLessStrategyNumber));
760786

@@ -854,6 +880,7 @@ range_binary_search(const RangeRelation *rangerel, FmgrInfo *cmp_func, Datum val
854880
{
855881
RangeEntry*ranges=dsm_array_get_pointer(&rangerel->ranges);
856882
RangeEntry*re;
883+
boolbyVal=rangerel->by_val;
857884
intcmp_min,
858885
cmp_max,
859886
i=0,
@@ -866,8 +893,11 @@ range_binary_search(const RangeRelation *rangerel, FmgrInfo *cmp_func, Datum val
866893
*foundPtr= false;
867894

868895
/* Check boundaries */
869-
cmp_min=FunctionCall2(cmp_func,value,ranges[0].min),
870-
cmp_max=FunctionCall2(cmp_func,value,ranges[rangerel->ranges.length-1].max);
896+
// cmp_min = FunctionCall2(cmp_func, value, ranges[0].min),
897+
// cmp_max = FunctionCall2(cmp_func, value, ranges[rangerel->ranges.length - 1].max);
898+
cmp_min=FunctionCall2(cmp_func,value,PATHMAN_GET_DATUM(ranges[0].min,byVal)),
899+
cmp_max=FunctionCall2(cmp_func,value,PATHMAN_GET_DATUM(ranges[rangerel->ranges.length-1].max,byVal));
900+
871901
if (cmp_min<0||cmp_max>0)
872902
{
873903
returni;
@@ -878,8 +908,10 @@ range_binary_search(const RangeRelation *rangerel, FmgrInfo *cmp_func, Datum val
878908
i=startidx+ (endidx-startidx) /2;
879909
Assert(i >=0&&i<rangerel->ranges.length);
880910
re=&ranges[i];
881-
cmp_min=FunctionCall2(cmp_func,value,re->min);
882-
cmp_max=FunctionCall2(cmp_func,value,re->max);
911+
// cmp_min = FunctionCall2(cmp_func, value, re->min);
912+
// cmp_max = FunctionCall2(cmp_func, value, re->max);
913+
cmp_min=FunctionCall2(cmp_func,value,PATHMAN_GET_DATUM(re->min,byVal));
914+
cmp_max=FunctionCall2(cmp_func,value,PATHMAN_GET_DATUM(re->max,byVal));
883915

884916
if (cmp_min >=0&&cmp_max<0)
885917
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp