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

Commit7e449c0

Browse files
committed
Simplify add_to_pathman_config, check hash function for expression for hash partitioning type.
1 parent6b87455 commit7e449c0

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

‎expected/pathman_permissions.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ GRANT SELECT ON permissions.user1_table TO user2;
1919
/* Should fail (don't own parent) */
2020
SET ROLE user2;
2121
SELECT create_range_partitions('permissions.user1_table', 'id', 1, 10, 2);
22+
WARNING: skipping "user1_table" --- only table or database owner can analyze it
2223
ERROR: only the owner or superuser can change partitioning configuration of table "user1_table"
2324
/* Should be ok */
2425
SET ROLE user1;

‎hash.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ BEGIN
3535
PERFORM @extschema@.common_relation_checks(parent_relid, expression);
3636

3737
/* Insert new entry to pathman config*/
38-
PERFORM @extschema@.add_to_pathman_config(parent_relid, expression,NULL, false);
38+
EXECUTE format('ANALYZE %s', parent_relid);
39+
PERFORM @extschema@.add_to_pathman_config(parent_relid, expression,NULL);
3940

4041
/* Create partitions*/
4142
PERFORM @extschema@.create_hash_partitions_internal(parent_relid,

‎init.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,9 +862,8 @@ LANGUAGE C STRICT;
862862
*/
863863
CREATEOR REPLACE FUNCTION @extschema@.add_to_pathman_config(
864864
parent_relidREGCLASS,
865-
attnameTEXT,
865+
expressionTEXT,
866866
range_intervalTEXT DEFAULTNULL,
867-
refresh_part_infoBOOL DEFAULT TRUE,
868867
parttypeINT4 DEFAULT0
869868
)
870869
RETURNSBOOLEANAS'pg_pathman','add_to_pathman_config'

‎range.sql

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ BEGIN
154154
END IF;
155155

156156
/* Insert new entry to pathman config*/
157+
EXECUTE format('ANALYZE %s', parent_relid);
157158
PERFORM @extschema@.add_to_pathman_config(parent_relid, expression,
158-
p_interval::TEXT, false);
159+
p_interval::TEXT);
159160

160161
/* Create sequence for child partitions names*/
161162
PERFORM @extschema@.create_or_replace_sequence(parent_relid);
@@ -251,8 +252,9 @@ BEGIN
251252
END IF;
252253

253254
/* Insert new entry to pathman config*/
255+
EXECUTE format('ANALYZE %s', parent_relid);
254256
PERFORM @extschema@.add_to_pathman_config(parent_relid, expression,
255-
p_interval::TEXT, false);
257+
p_interval::TEXT);
256258

257259
/* Create sequence for child partitions names*/
258260
PERFORM @extschema@.create_or_replace_sequence(parent_relid);
@@ -310,7 +312,8 @@ BEGIN
310312
bounds[array_length(bounds,1)-1]);
311313

312314
/* Insert new entry to pathman config*/
313-
PERFORM @extschema@.add_to_pathman_config(parent_relid, expression,NULL, false,2);
315+
EXECUTE format('ANALYZE %s', parent_relid);
316+
PERFORM @extschema@.add_to_pathman_config(parent_relid, expression,NULL,2);
314317

315318
/* Create sequence for child partitions names*/
316319
PERFORM @extschema@.create_or_replace_sequence(parent_relid);
@@ -360,8 +363,9 @@ BEGIN
360363
end_value);
361364

362365
/* Insert new entry to pathman config*/
366+
EXECUTE format('ANALYZE %s', parent_relid);
363367
PERFORM @extschema@.add_to_pathman_config(parent_relid, expression,
364-
p_interval::TEXT, false);
368+
p_interval::TEXT);
365369

366370
/* Create sequence for child partitions names*/
367371
PERFORM @extschema@.create_or_replace_sequence(parent_relid);
@@ -417,8 +421,9 @@ BEGIN
417421
end_value);
418422

419423
/* Insert new entry to pathman config*/
424+
EXECUTE format('ANALYZE %s', parent_relid);
420425
PERFORM @extschema@.add_to_pathman_config(parent_relid, expression,
421-
p_interval::TEXT, false);
426+
p_interval::TEXT);
422427

423428
/* Create sequence for child partitions names*/
424429
PERFORM @extschema@.create_or_replace_sequence(parent_relid);

‎src/pl_funcs.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include"access/nbtree.h"
2323
#include"access/htup_details.h"
2424
#include"catalog/indexing.h"
25+
#include"catalog/pg_inherits_fn.h"
2526
#include"catalog/pg_trigger.h"
2627
#include"catalog/pg_type.h"
2728
#include"commands/tablespace.h"
@@ -709,7 +710,6 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
709710
Relationpathman_config;
710711
Datumvalues[Natts_pathman_config];
711712
boolisnull[Natts_pathman_config];
712-
boolrefresh_part_info;
713713
HeapTuplehtup;
714714

715715
Oidexpr_type;
@@ -745,13 +745,23 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
745745
}
746746

747747
/* Select partitioning type */
748-
parttype=PG_GETARG_INT32(4);
748+
parttype=PG_GETARG_INT32(3);
749749
if ((parttype!=PT_HASH)&& (parttype!=PT_RANGE))
750750
parttype=PG_ARGISNULL(2) ?PT_HASH :PT_RANGE;
751751

752752
/* Parse and check expression */
753753
expr_datum=plan_partitioning_expression(relid,expression,&expr_type);
754754

755+
/* Expression for range partitions should be hashable */
756+
if (parttype==PT_HASH)
757+
{
758+
TypeCacheEntry*tce;
759+
760+
tce=lookup_type_cache(expr_type,TYPECACHE_HASH_PROC);
761+
if (tce->hash_proc==InvalidOid)
762+
elog(ERROR,"partitioning expression should be hashable");
763+
}
764+
755765
/*
756766
* Initialize columns (partrel, attname, parttype, range_interval).
757767
*/
@@ -790,10 +800,8 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
790800

791801
heap_close(pathman_config,RowExclusiveLock);
792802

793-
/* FIXME: check pg_inherits instead of this argument */
794-
refresh_part_info=PG_GETARG_BOOL(3);
795-
796-
if (refresh_part_info)
803+
/* update caches only if this relation has children */
804+
if (has_subclass(relid))
797805
{
798806
/* Now try to create a PartRelationInfo */
799807
PG_TRY();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp