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

Commitfa6f4c1

Browse files
committed
clean code, take lock in PathmanRenameConstraint()
1 parent1277897 commitfa6f4c1

File tree

6 files changed

+57
-56
lines changed

6 files changed

+57
-56
lines changed

‎src/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ pathman_process_utility_hook(Node *parsetree,
653653
* Rename check constraint of a table if it is a partition managed
654654
* by pg_pathman
655655
*/
656-
PathmanDoRenameConstraint((RenameStmt*)parsetree);
656+
PathmanRenameConstraint((RenameStmt*)parsetree);
657657
}
658658
}
659659

‎src/init.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,18 @@ find_inheritance_children_array(Oid parentrelId,
593593
/*
594594
* Generate check constraint name for a partition.
595595
*
596-
*This function does not perform sanity checks at all.
596+
*These functions does not perform sanity checks at all.
597597
*/
598598
char*
599-
build_check_constraint_name_internal(Oidrelid,AttrNumberattno)
599+
build_check_constraint_name_relid_internal(Oidrelid,AttrNumberattno)
600600
{
601-
returnbuild_check_constraint_name_by_relname(get_rel_name(relid),attno);
601+
returnbuild_check_constraint_name_relname_internal(get_rel_name(relid),attno);
602+
}
603+
604+
char*
605+
build_check_constraint_name_relname_internal(char*relname,AttrNumberattno)
606+
{
607+
returnpsprintf("pathman_%s_%u_check",relname,attno);
602608
}
603609

604610
/*
@@ -807,7 +813,7 @@ get_partition_constraint_expr(Oid partition, AttrNumber part_attno)
807813
boolconbin_isnull;
808814
Expr*expr;/* expression tree for constraint */
809815

810-
conname=build_check_constraint_name_internal(partition,part_attno);
816+
conname=build_check_constraint_name_relid_internal(partition,part_attno);
811817
conid=get_relation_constraint_oid(partition,conname, true);
812818
if (conid==InvalidOid)
813819
{

‎src/init.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ extern PathmanInitState pg_pathman_init_state;
8686
pg_pathman_init_state.initialization_needed = true; \
8787
} while (0)
8888

89-
/*
90-
* Generate check constraint name for given relname
91-
*/
92-
staticinlinechar*
93-
build_check_constraint_name_by_relname(char*relname,AttrNumberattno)
94-
{
95-
returnpsprintf("pathman_%s_%u_check",relname,attno);
96-
}
97-
9889

9990
/*
10091
* Save and restore PathmanInitState.
@@ -132,8 +123,11 @@ find_children_status find_inheritance_children_array(Oid parentrelId,
132123
uint32*children_size,
133124
Oid**children);
134125

135-
char*build_check_constraint_name_internal(Oidrelid,
136-
AttrNumberattno);
126+
char*build_check_constraint_name_relid_internal(Oidrelid,
127+
AttrNumberattno);
128+
129+
char*build_check_constraint_name_relname_internal(char*relname,
130+
AttrNumberattno);
137131

138132
boolpathman_config_contains_relation(Oidrelid,
139133
Datum*values,

‎src/pl_funcs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ build_check_constraint_name_attnum(PG_FUNCTION_ARGS)
521521
elog(ERROR,"Cannot build check constraint name: "
522522
"invalid attribute number %i",attnum);
523523

524-
result=build_check_constraint_name_internal(relid,attnum);
524+
result=build_check_constraint_name_relid_internal(relid,attnum);
525525

526526
PG_RETURN_TEXT_P(cstring_to_text(quote_identifier(result)));
527527
}
@@ -541,7 +541,7 @@ build_check_constraint_name_attname(PG_FUNCTION_ARGS)
541541
elog(ERROR,"relation \"%s\" has no column \"%s\"",
542542
get_rel_name_or_relid(relid),text_to_cstring(attname));
543543

544-
result=build_check_constraint_name_internal(relid,attnum);
544+
result=build_check_constraint_name_relid_internal(relid,attnum);
545545

546546
PG_RETURN_TEXT_P(cstring_to_text(quote_identifier(result)));
547547
}

‎src/utility_stmt_hooking.c

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -626,44 +626,45 @@ prepare_rri_fdw_for_copy(EState *estate,
626626
}
627627

628628
/*
629-
* Rename check constraint of table if it isa partition
629+
* Rename check constraint of table if it'sa partition
630630
*/
631631
void
632-
PathmanDoRenameConstraint(constRenameStmt*stmt)
632+
PathmanRenameConstraint(constRenameStmt*stmt)
633633
{
634-
Oidpartition=RangeVarGetRelid(stmt->relation,NoLock, true);
635-
Oidparent=get_rel_parent(partition);
636-
637-
if (partition!=InvalidOid&&parent!=InvalidOid)
638-
{
639-
char*old_constraint_name,
640-
*new_constraint_name;
641-
constPartRelationInfo*prel=get_pathman_relation_info(parent);
642-
643-
if (prel)
644-
{
645-
RangeVar*rngVar;
646-
RenameStmt*s;
647-
648-
/* Generate old constraint name */
649-
old_constraint_name=build_check_constraint_name_by_relname(
650-
get_rel_name(partition),
651-
prel->attnum);
652-
653-
/* Generate new constraint name */
654-
new_constraint_name=build_check_constraint_name_by_relname(
655-
stmt->newname,
656-
prel->attnum);
657-
658-
/* Build check constraint RENAME statement */
659-
s=makeNode(RenameStmt);
660-
s->renameType=OBJECT_TABCONSTRAINT;
661-
s->relation=stmt->relation;
662-
s->subname=old_constraint_name;
663-
s->newname=new_constraint_name;
664-
s->missing_ok= false;
665-
666-
RenameConstraint(s);
667-
}
668-
}
634+
Oidpartition_relid,
635+
parent_relid;
636+
char*old_constraint_name,
637+
*new_constraint_name;
638+
RenameStmt*rename_stmt;
639+
constPartRelationInfo*prel;
640+
641+
partition_relid=RangeVarGetRelid(stmt->relation,AccessShareLock, false);
642+
parent_relid=get_rel_parent(partition_relid);
643+
644+
/* Skip if there's no parent */
645+
if (!OidIsValid(parent_relid))return;
646+
647+
/* Fetch partitioning data */
648+
prel=get_pathman_relation_info(parent_relid);
649+
650+
/* Skip if this table is not partitioned */
651+
if (!prel)return;
652+
653+
/* Generate old constraint name */
654+
old_constraint_name=build_check_constraint_name_relid_internal(partition_relid,
655+
prel->attnum);
656+
657+
/* Generate new constraint name */
658+
new_constraint_name=build_check_constraint_name_relname_internal(stmt->newname,
659+
prel->attnum);
660+
661+
/* Build check constraint RENAME statement */
662+
rename_stmt=makeNode(RenameStmt);
663+
rename_stmt->renameType=OBJECT_TABCONSTRAINT;
664+
rename_stmt->relation=stmt->relation;
665+
rename_stmt->subname=old_constraint_name;
666+
rename_stmt->newname=new_constraint_name;
667+
rename_stmt->missing_ok= false;
668+
669+
RenameConstraint(rename_stmt);
669670
}

‎src/utility_stmt_hooking.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919

2020
boolis_pathman_related_copy(Node*parsetree);
2121
voidPathmanDoCopy(constCopyStmt*stmt,constchar*queryString,uint64*processed);
22-
voidPathmanDoRenameConstraint(constRenameStmt*stmt);
22+
voidPathmanRenameConstraint(constRenameStmt*stmt);
2323

2424
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp