Skip to content

Commit dc86c76

Browse files
committed
call fill_type_cmp_fmgr_info() in handle_binary_opexpr() only for RANGE part. cases, improve fill_type_cmp_fmgr_info()
1 parent 010bf7e commit dc86c76

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

expected/pathman_basic.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,30 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.sql_inline_func(1);
11141114
DROP FUNCTION test.sql_inline_func(int);
11151115
DROP TABLE test.sql_inline CASCADE;
11161116
NOTICE: drop cascades to 3 other objects
1117+
/*
1118+
* Test by @baiyinqiqi (issue #60)
1119+
*/
1120+
CREATE TABLE test.hash_varchar(val VARCHAR(40) NOT NULL);
1121+
INSERT INTO test.hash_varchar SELECT generate_series(1, 20);
1122+
SELECT pathman.create_hash_partitions('test.hash_varchar', 'val', 4);
1123+
create_hash_partitions
1124+
------------------------
1125+
4
1126+
(1 row)
1127+
1128+
SELECT * FROM test.hash_varchar WHERE val = 'a';
1129+
val
1130+
-----
1131+
(0 rows)
1132+
1133+
SELECT * FROM test.hash_varchar WHERE val = '12'::TEXT;
1134+
val
1135+
-----
1136+
12
1137+
(1 row)
1138+
1139+
DROP TABLE test.hash_varchar CASCADE;
1140+
NOTICE: drop cascades to 4 other objects
11171141
/*
11181142
* Test CTE query
11191143
*/

sql/pathman_basic.sql

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.sql_inline_func(1);
280280
DROP FUNCTION test.sql_inline_func(int);
281281
DROP TABLE test.sql_inline CASCADE;
282282

283+
/*
284+
* Test by @baiyinqiqi (issue #60)
285+
*/
286+
CREATE TABLE test.hash_varchar(val VARCHAR(40) NOT NULL);
287+
INSERT INTO test.hash_varchar SELECT generate_series(1, 20);
288+
289+
SELECT pathman.create_hash_partitions('test.hash_varchar', 'val', 4);
290+
SELECT * FROM test.hash_varchar WHERE val = 'a';
291+
SELECT * FROM test.hash_varchar WHERE val = '12'::TEXT;
292+
293+
DROP TABLE test.hash_varchar CASCADE;
294+
283295
/*
284296
* Test CTE query
285297
*/
@@ -291,7 +303,6 @@ EXPLAIN (COSTS OFF)
291303
WITH ttt AS (SELECT * FROM test.hash_rel WHERE value = 2)
292304
SELECT * FROM ttt;
293305

294-
295306
/*
296307
* Test CTE query - by @parihaaraka (add varno to WalkerContext)
297308
*/

src/pg_pathman.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,6 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
704704
{
705705
int strategy;
706706
TypeCacheEntry *tce;
707-
FmgrInfo cmp_func;
708707
Oid vartype;
709708
const OpExpr *expr = (const OpExpr *) result->orig;
710709
const PartRelationInfo *prel = context->prel;
@@ -730,10 +729,6 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
730729
if (strategy == 0)
731730
goto binary_opexpr_return;
732731

733-
fill_type_cmp_fmgr_info(&cmp_func,
734-
getBaseType(c->consttype),
735-
getBaseType(prel->atttype));
736-
737732
switch (prel->parttype)
738733
{
739734
case PT_HASH:
@@ -754,6 +749,12 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
754749

755750
case PT_RANGE:
756751
{
752+
FmgrInfo cmp_func;
753+
754+
fill_type_cmp_fmgr_info(&cmp_func,
755+
getBaseType(c->consttype),
756+
getBaseType(prel->atttype));
757+
757758
select_range_partitions(c->constvalue,
758759
&cmp_func,
759760
PrelGetRangesArray(context->prel),

src/utils.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,36 @@ void
6464
fill_type_cmp_fmgr_info(FmgrInfo *finfo, Oid type1, Oid type2)
6565
{
6666
Oid cmp_proc_oid;
67-
TypeCacheEntry *tce;
67+
TypeCacheEntry *tce_1,
68+
*tce_2;
6869

6970
if (IsBinaryCoercible(type1, type2))
7071
type1 = type2;
7172

7273
else if (IsBinaryCoercible(type2, type1))
7374
type2 = type1;
7475

75-
tce = lookup_type_cache(type1, TYPECACHE_BTREE_OPFAMILY);
76+
tce_1 = lookup_type_cache(type1, TYPECACHE_BTREE_OPFAMILY);
77+
tce_2 = lookup_type_cache(type2, TYPECACHE_BTREE_OPFAMILY);
7678

77-
cmp_proc_oid = get_opfamily_proc(tce->btree_opf,
78-
type1,
79-
type2,
79+
if (tce_1->btree_opf != tce_2->btree_opf)
80+
goto fill_type_cmp_fmgr_info_error;
81+
82+
cmp_proc_oid = get_opfamily_proc(tce_1->btree_opf,
83+
tce_1->btree_opintype,
84+
tce_2->btree_opintype,
8085
BTORDER_PROC);
8186

8287
if (cmp_proc_oid == InvalidOid)
83-
elog(ERROR, "missing comparison function for types %s & %s",
84-
format_type_be(type1), format_type_be(type2));
88+
goto fill_type_cmp_fmgr_info_error;
8589

8690
fmgr_info(cmp_proc_oid, finfo);
8791

88-
return;
92+
return; /* exit safely */
93+
94+
fill_type_cmp_fmgr_info_error:
95+
elog(ERROR, "missing comparison function for types %s & %s",
96+
format_type_be(type1), format_type_be(type2));
8997
}
9098

9199
List *

0 commit comments

Comments
 (0)