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

Commitbd91a69

Browse files
committed
pathman: minor refactoring
1 parent3f37475 commitbd91a69

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

‎contrib/pg_pathman/init.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include"utils/lsyscache.h"
2222
#include"utils/bytea.h"
2323
#include"utils/snapmgr.h"
24+
#include"optimizer/clauses.h"
2425

2526

2627
HTAB*relations=NULL;
@@ -32,6 +33,7 @@ static bool globalByVal;
3233

3334
staticboolvalidate_range_constraint(Expr*,PartRelationInfo*,Datum*,Datum*);
3435
staticboolvalidate_hash_constraint(Expr*expr,PartRelationInfo*prel,int*hash);
36+
staticboolread_opexpr_const(OpExpr*opexpr,intvarattno,Datum*val);
3537
staticintcmp_range_entries(constvoid*p1,constvoid*p2);
3638

3739
Size
@@ -453,11 +455,7 @@ validate_range_constraint(Expr *expr, PartRelationInfo *prel, Datum *min, Datum
453455
OpExpr*opexpr;
454456

455457
/* it should be an AND operator on top */
456-
if ( !(IsA(expr,BoolExpr)&&boolexpr->boolop==AND_EXPR) )
457-
return false;
458-
459-
/* and it should have exactly two operands */
460-
if (list_length(boolexpr->args)!=2)
458+
if (!and_clause((Node*)expr))
461459
return false;
462460

463461
tce=lookup_type_cache(prel->atttype,TYPECACHE_EQ_OPR |TYPECACHE_LT_OPR |TYPECACHE_GT_OPR);
@@ -466,36 +464,43 @@ validate_range_constraint(Expr *expr, PartRelationInfo *prel, Datum *min, Datum
466464
opexpr= (OpExpr*)linitial(boolexpr->args);
467465
if (get_op_opfamily_strategy(opexpr->opno,tce->btree_opf)==BTGreaterEqualStrategyNumber)
468466
{
469-
Node*left=linitial(opexpr->args);
470-
Node*right=lsecond(opexpr->args);
471-
if ( !IsA(left,Var)|| !IsA(right,Const) )
472-
return false;
473-
if ( ((Var*)left)->varattno!=prel->attnum )
467+
if (!read_opexpr_const(opexpr,prel->attnum,min))
474468
return false;
475-
*min= ((Const*)right)->constvalue;
476469
}
477470
else
478471
return false;
479472

480-
/* TODO: rewrite this */
481473
/* check that right operand is < operator */
482474
opexpr= (OpExpr*)lsecond(boolexpr->args);
483475
if (get_op_opfamily_strategy(opexpr->opno,tce->btree_opf)==BTLessStrategyNumber)
484476
{
485-
Node*left=linitial(opexpr->args);
486-
Node*right=lsecond(opexpr->args);
487-
if ( !IsA(left,Var)|| !IsA(right,Const) )
488-
return false;
489-
if ( ((Var*)left)->varattno!=prel->attnum )
477+
if (!read_opexpr_const(opexpr,prel->attnum,max))
490478
return false;
491-
*max= ((Const*)right)->constvalue;
492479
}
493480
else
494481
return false;
495482

496483
return true;
497484
}
498485

486+
/*
487+
* Reads const value from expressions of kind: VAR >= CONST or VAR < CONST
488+
*/
489+
staticbool
490+
read_opexpr_const(OpExpr*opexpr,intvarattno,Datum*val)
491+
{
492+
Node*left=linitial(opexpr->args);
493+
Node*right=lsecond(opexpr->args);
494+
495+
if ( !IsA(left,Var)|| !IsA(right,Const) )
496+
return false;
497+
if ( ((Var*)left)->varattno!=varattno )
498+
return false;
499+
*val= ((Const*)right)->constvalue;
500+
501+
return true;
502+
}
503+
499504
/*
500505
* Validate hash constraint. It MUST have the exact format
501506
* VARIABLE % CONST = CONST

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp