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

Commitdc0a854

Browse files
committed
change signature of function build_hash_condition(), more tests
1 parent6b88f51 commitdc0a854

File tree

5 files changed

+63
-17
lines changed

5 files changed

+63
-17
lines changed

‎expected/pathman_calamity.out

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,44 @@ SELECT debug_capture();
1212
set client_min_messages = NOTICE;
1313
/* create table to be partitioned */
1414
CREATE TABLE calamity.part_test(val serial);
15+
/* check function build_hash_condition() */
16+
SELECT build_hash_condition('int4', 'val', 10, 1);
17+
build_hash_condition
18+
-------------------------------------------------
19+
public.get_hash_part_idx(hashint4(val), 10) = 1
20+
(1 row)
21+
22+
SELECT build_hash_condition('text', 'val', 10, 1);
23+
build_hash_condition
24+
-------------------------------------------------
25+
public.get_hash_part_idx(hashtext(val), 10) = 1
26+
(1 row)
27+
28+
SELECT build_hash_condition('int4', 'val', 1, 1);
29+
ERROR: 'partition_index' must be lower than 'partitions_count'
30+
SELECT build_hash_condition('int4', 'val', 10, 20);
31+
ERROR: 'partition_index' must be lower than 'partitions_count'
32+
SELECT build_hash_condition('text', 'val', 10, NULL) IS NULL;
33+
?column?
34+
----------
35+
t
36+
(1 row)
37+
38+
SELECT build_hash_condition('calamity.part_test', 'val', 10, 1);
39+
ERROR: no hash function for type calamity.part_test
40+
/* check function build_range_condition() */
41+
SELECT build_range_condition('val', 10, 20);
42+
build_range_condition
43+
----------------------------
44+
val >= '10' AND val < '20'
45+
(1 row)
46+
47+
SELECT build_range_condition('val', 10, NULL) IS NULL;
48+
?column?
49+
----------
50+
t
51+
(1 row)
52+
1553
/* check function validate_relname() */
1654
SELECT validate_relname('calamity.part_test');
1755
validate_relname

‎hash.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ LANGUAGE C STRICT;
289289
* Build hash condition for a CHECK CONSTRAINT
290290
*/
291291
CREATEOR REPLACE FUNCTION @extschema@.build_hash_condition(
292-
parent_relidREGCLASS,
292+
attribute_typeREGTYPE,
293293
attributeTEXT,
294-
part_countINT4,
295-
part_idxINT4)
294+
partitions_countINT4,
295+
partitions_indexINT4)
296296
RETURNSTEXTAS'pg_pathman','build_hash_condition'
297297
LANGUAGE C STRICT;

‎range.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,11 +1228,11 @@ SET client_min_messages = WARNING;
12281228
* Construct CHECK constraint condition for a range partition.
12291229
*/
12301230
CREATEOR REPLACE FUNCTION @extschema@.build_range_condition(
1231-
p_attnameTEXT,
1231+
attributeTEXT,
12321232
start_valueANYELEMENT,
12331233
end_valueANYELEMENT)
12341234
RETURNSTEXTAS'pg_pathman','build_range_condition'
1235-
LANGUAGE C;
1235+
LANGUAGE C STRICT;
12361236

12371237
CREATEOR REPLACE FUNCTION @extschema@.build_sequence_name(
12381238
parent_relidREGCLASS)

‎sql/pathman_calamity.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ set client_min_messages = NOTICE;
1414
CREATETABLEcalamity.part_test(valserial);
1515

1616

17+
/* check function build_hash_condition()*/
18+
SELECT build_hash_condition('int4','val',10,1);
19+
SELECT build_hash_condition('text','val',10,1);
20+
SELECT build_hash_condition('int4','val',1,1);
21+
SELECT build_hash_condition('int4','val',10,20);
22+
SELECT build_hash_condition('text','val',10,NULL) ISNULL;
23+
SELECT build_hash_condition('calamity.part_test','val',10,1);
24+
25+
/* check function build_range_condition()*/
26+
SELECT build_range_condition('val',10,20);
27+
SELECT build_range_condition('val',10,NULL) ISNULL;
28+
1729
/* check function validate_relname()*/
1830
SELECT validate_relname('calamity.part_test');
1931
SELECT validate_relname(1::REGCLASS);

‎src/pl_hash_funcs.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,24 @@ get_hash_part_idx(PG_FUNCTION_ARGS)
9191
Datum
9292
build_hash_condition(PG_FUNCTION_ARGS)
9393
{
94-
Oidparent=PG_GETARG_OID(0);
94+
Oidatttype=PG_GETARG_OID(0);
9595
text*attname=PG_GETARG_TEXT_P(1);
96-
uint32part_count=PG_GETARG_UINT32(2);
97-
uint32part_idx=PG_GETARG_UINT32(3);
96+
uint32part_count=PG_GETARG_UINT32(2),
97+
part_idx=PG_GETARG_UINT32(3);
9898

9999
TypeCacheEntry*tce;
100-
Oidattype;
101100
char*attname_cstring=text_to_cstring(attname);
102101

103102
char*result;
104103

105104
if (part_idx >=part_count)
106-
elog(ERROR,"'part_idx' must be lower than 'part_count'");
105+
elog(ERROR,"'partition_index' must be lower than 'partitions_count'");
107106

108-
/* Get attribute type and its hash function oid */
109-
attype=get_attribute_type(parent,attname_cstring, false);
110-
if (attype==InvalidOid)
111-
elog(ERROR,"relation \"%s\" has no attribute \"%s\"",
112-
get_rel_name(parent),
113-
attname_cstring);
107+
tce=lookup_type_cache(atttype,TYPECACHE_HASH_PROC);
114108

115-
tce=lookup_type_cache(attype,TYPECACHE_HASH_PROC);
109+
/* Check that HASH function exists */
110+
if (!OidIsValid(tce->hash_proc))
111+
elog(ERROR,"no hash function for type %s",format_type_be(atttype));
116112

117113
/* Create hash condition CSTRING */
118114
result=psprintf("%s.get_hash_part_idx(%s(%s), %u) = %u",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp