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

Commit0927b9f

Browse files
committed
EPQ: fix multilevel (see router_lazy_init_constraint())
1 parentc3399f3 commit0927b9f

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

‎src/include/relation_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ void shout_if_prel_is_invalid(const Oid parent_oid,
367367
constPartTypeexpected_part_type);
368368

369369
/* Bounds cache */
370-
Expr*get_partition_constraint_expr(Oidpartition);
371370
voidforget_bounds_of_partition(Oidpartition);
372371
PartBoundInfo*get_bounds_of_partition(Oidpartition,constPartRelationInfo*prel);
372+
Expr*get_partition_constraint_expr(Oidpartition,boolraise_error);
373373
voidinvalidate_bounds_cache(void);
374374

375375
/* Parents cache */

‎src/partition_router.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include"commands/trigger.h"
2121
#include"executor/nodeModifyTable.h"
2222
#include"foreign/fdwapi.h"
23+
#include"optimizer/clauses.h"
2324
#include"storage/bufmgr.h"
2425
#include"utils/guc.h"
2526
#include"utils/rel.h"
@@ -378,12 +379,33 @@ router_lazy_init_junkfilter(PartitionRouterState *state, EState *estate)
378379
staticvoid
379380
router_lazy_init_constraint(PartitionRouterState*state)
380381
{
381-
Relationrel=state->current_rri->ri_RelationDesc;
382-
383382
if (state->constraint==NULL)
384383
{
385-
Expr*expr=get_partition_constraint_expr(RelationGetRelid(rel));
386-
state->constraint=ExecInitExpr(expr,NULL);
384+
Relationrel=state->current_rri->ri_RelationDesc;
385+
Oidrelid=RelationGetRelid(rel);
386+
List*clauses=NIL;
387+
Expr*expr;
388+
389+
while (OidIsValid(relid))
390+
{
391+
/* It's probably OK if expression is NULL */
392+
expr=get_partition_constraint_expr(relid, false);
393+
expr=expression_planner(expr);
394+
395+
if (!expr)
396+
break;
397+
398+
/* Add this constraint to set */
399+
clauses=lappend(clauses,expr);
400+
401+
/* Consider parent's check constraint as well */
402+
relid=get_parent_of_partition(relid);
403+
}
404+
405+
if (!clauses)
406+
elog(ERROR,"no recheck constraint for relid %d",relid);
407+
408+
state->constraint=ExecInitExpr(make_ands_explicit(clauses),NULL);
387409
}
388410
}
389411

‎src/relation_info.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ get_bounds_of_partition(Oid partition, const PartRelationInfo *prel)
10001000
pbin_local.byval=prel->ev_byval;
10011001

10021002
/* Try to build constraint's expression tree (may emit ERROR) */
1003-
con_expr=get_partition_constraint_expr(partition);
1003+
con_expr=get_partition_constraint_expr(partition, true);
10041004

10051005
/* Grab bounds/hash and fill in 'pbin_local' (may emit ERROR) */
10061006
fill_pbin_with_bounds(&pbin_local,prel,con_expr);
@@ -1046,7 +1046,7 @@ invalidate_bounds_cache(void)
10461046
* build_check_constraint_name_internal() is used to build conname.
10471047
*/
10481048
Expr*
1049-
get_partition_constraint_expr(Oidpartition)
1049+
get_partition_constraint_expr(Oidpartition,boolraise_error)
10501050
{
10511051
Oidconid;/* constraint Oid */
10521052
char*conname;/* constraint name */
@@ -1060,11 +1060,12 @@ get_partition_constraint_expr(Oid partition)
10601060

10611061
if (!OidIsValid(conid))
10621062
{
1063-
DisablePathman();/* disable pg_pathman since config is broken */
1063+
if (!raise_error)
1064+
returnNULL;
1065+
10641066
ereport(ERROR,
10651067
(errmsg("constraint \"%s\" of partition \"%s\" does not exist",
1066-
conname,get_rel_name_or_relid(partition)),
1067-
errhint(INIT_ERROR_HINT)));
1068+
conname,get_rel_name_or_relid(partition))));
10681069
}
10691070

10701071
con_tuple=SearchSysCache1(CONSTROID,ObjectIdGetDatum(conid));
@@ -1073,11 +1074,12 @@ get_partition_constraint_expr(Oid partition)
10731074
&conbin_isnull);
10741075
if (conbin_isnull)
10751076
{
1076-
DisablePathman();/* disable pg_pathman since config is broken */
1077-
ereport(WARNING,
1077+
if (!raise_error)
1078+
returnNULL;
1079+
1080+
ereport(ERROR,
10781081
(errmsg("constraint \"%s\" of partition \"%s\" has NULL conbin",
1079-
conname,get_rel_name_or_relid(partition)),
1080-
errhint(INIT_ERROR_HINT)));
1082+
conname,get_rel_name_or_relid(partition))));
10811083
pfree(conname);
10821084

10831085
returnNULL;/* could not parse */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp