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

Commitdec354c

Browse files
committed
Fix a number of places that made faulty assumptions about
what is_opclause will accept.
1 parent5500039 commitdec354c

File tree

6 files changed

+127
-56
lines changed

6 files changed

+127
-56
lines changed

‎src/backend/optimizer/path/clausesel.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.17 1999/02/13 23:16:15 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.18 1999/02/15 01:06:57 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -206,7 +206,7 @@ compute_selec(Query *root, List *clauses, List *or_selectivities)
206206
Costs1=0;
207207
List*clause=lfirst(clauses);
208208

209-
if (clauses==NULL)
209+
if (clause==NULL)
210210
s1=1.0;
211211
elseif (IsA(clause,Param))
212212
{
@@ -351,7 +351,7 @@ compute_selec(Query *root, List *clauses, List *or_selectivities)
351351
* an 'or' clause, but rather that of the single clause.
352352
*/
353353

354-
if (length(clauses)<2)
354+
if (lnext(clauses)==NIL)
355355
returns1;
356356
else
357357
{

‎src/backend/optimizer/path/indxpath.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.44 1999/02/13 23:16:16 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.45 1999/02/15 01:06:57 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -324,25 +324,25 @@ match_index_orclause(RelOptInfo *rel,
324324
{
325325
clause=lfirst(clist);
326326

327-
if (is_opclause(clause)&&
328-
op_class(((Oper*) ((Expr*)clause)->oper)->opno,
329-
xclass,index->relam)&&
330-
((match_index_to_operand(indexkey,
331-
(Expr*)get_leftop((Expr*)clause),
332-
rel,
333-
index)&&
334-
IsA(get_rightop((Expr*)clause),Const))||
335-
(match_index_to_operand(indexkey,
336-
(Expr*)get_rightop((Expr*)clause),
337-
rel,
338-
index)&&
339-
IsA(get_leftop((Expr*)clause),Const))))
340-
lfirst(matching_indices)=lcons(index,lfirst(matching_indices));
327+
if (is_opclause(clause))
328+
{
329+
Expr*left= (Expr*)get_leftop((Expr*)clause);
330+
Expr*right= (Expr*)get_rightop((Expr*)clause);
331+
if (left&&right&&
332+
op_class(((Oper*) ((Expr*)clause)->oper)->opno,
333+
xclass,index->relam)&&
334+
((IsA(right,Const)&&
335+
match_index_to_operand(indexkey,left,rel,index))||
336+
(IsA(left,Const)&&
337+
match_index_to_operand(indexkey,right,rel,index))))
338+
lfirst(matching_indices)=lcons(index,
339+
lfirst(matching_indices));
340+
}
341341

342342
matching_indices=lnext(matching_indices);
343343
}
344-
returnindex_list;
345344

345+
returnindex_list;
346346
}
347347

348348
/****************************************************************************
@@ -1019,6 +1019,7 @@ clause_pred_clause_test(Expr *predicate, Node *clause)
10191019
/* Check the basic form; for now, only allow the simplest case */
10201020
if (!is_opclause(clause)||
10211021
!IsA(clause_var,Var)||
1022+
clause_const==NULL||
10221023
!IsA(clause_const,Const)||
10231024
!IsA(predicate->oper,Oper)||
10241025
!IsA(pred_var,Var)||

‎src/backend/optimizer/plan/createplan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.46 1999/02/13 23:16:27 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.47 1999/02/15 01:06:58 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -780,6 +780,7 @@ switch_outer(List *clauses)
780780
{
781781
clause=lfirst(i);
782782
op= (Node*)get_rightop(clause);
783+
Assert(op!= (Node*)NULL);
783784
if (IsA(op,ArrayRef))
784785
op= ((ArrayRef*)op)->refexpr;
785786
Assert(IsA(op,Var));

‎src/backend/optimizer/plan/initsplan.c

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.24 1999/02/14 04:56:50 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.25 1999/02/15 01:06:58 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -367,25 +367,42 @@ set_joininfo_mergeable_hashable(List *rel_list)
367367
staticMergeOrder*
368368
mergejoinop(Expr*clause)
369369
{
370-
OidleftOp,
370+
Var*left,
371+
*right;
372+
Oidopno,
373+
leftOp,
371374
rightOp;
372375
boolsortable;
373376

374-
sortable=op_mergejoinable(((Oper*)clause->oper)->opno,
375-
(get_leftop(clause))->vartype,
376-
(get_rightop(clause))->vartype,
377+
if (!is_opclause((Node*)clause))
378+
returnNULL;
379+
380+
left=get_leftop(clause);
381+
right=get_rightop(clause);
382+
383+
/* caution: is_opclause accepts more than I do, so check it */
384+
if (!right)
385+
returnNULL;/* unary opclauses need not apply */
386+
if (!IsA(left,Var)|| !IsA(right,Var))
387+
returnNULL;
388+
389+
opno= ((Oper*)clause->oper)->opno;
390+
391+
sortable=op_mergejoinable(opno,
392+
left->vartype,
393+
right->vartype,
377394
&leftOp,
378395
&rightOp);
379396

380397
if (sortable)
381398
{
382399
MergeOrder*morder=makeNode(MergeOrder);
383400

384-
morder->join_operator=((Oper*)clause->oper)->opno;
401+
morder->join_operator=opno;
385402
morder->left_operator=leftOp;
386403
morder->right_operator=rightOp;
387-
morder->left_type=(get_leftop(clause))->vartype;
388-
morder->right_type=(get_rightop(clause))->vartype;
404+
morder->left_type=left->vartype;
405+
morder->right_type=right->vartype;
389406
returnmorder;
390407
}
391408
else
@@ -401,7 +418,22 @@ mergejoinop(Expr *clause)
401418
staticOid
402419
hashjoinop(Expr*clause)
403420
{
404-
return (op_hashjoinable(((Oper*)clause->oper)->opno,
405-
(get_leftop(clause))->vartype,
406-
(get_rightop(clause))->vartype));
421+
Var*left,
422+
*right;
423+
424+
if (!is_opclause((Node*)clause))
425+
returnInvalidOid;
426+
427+
left=get_leftop(clause);
428+
right=get_rightop(clause);
429+
430+
/* caution: is_opclause accepts more than I do, so check it */
431+
if (!right)
432+
returnInvalidOid;/* unary opclauses need not apply */
433+
if (!IsA(left,Var)|| !IsA(right,Var))
434+
returnInvalidOid;
435+
436+
returnop_hashjoinable(((Oper*)clause->oper)->opno,
437+
left->vartype,
438+
right->vartype);
407439
}

‎src/backend/optimizer/plan/setrefs.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.39 1999/02/13 23:16:33 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.40 1999/02/15 01:06:58 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -290,6 +290,8 @@ replace_clause_joinvar_refs(Expr *clause,
290290
{
291291
List*temp=NULL;
292292

293+
if (clause==NULL)
294+
returnNULL;
293295
if (IsA(clause,Var))
294296
{
295297
temp= (List*)replace_joinvar_refs((Var*)clause,
@@ -586,6 +588,8 @@ replace_result_clause(Node *clause,
586588
{
587589
List*t;
588590

591+
if (clause==NULL)
592+
return;
589593
if (IsA(clause,Var))
590594
{
591595
TargetEntry*subplanVar;

‎src/backend/optimizer/prep/prepqual.c

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepqual.c,v 1.13 1999/02/13 23:16:37 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepqual.c,v 1.14 1999/02/15 01:06:59 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -106,10 +106,17 @@ find_nots(Expr *qual)
106106

107107
if (is_opclause((Node*)qual))
108108
{
109-
return (make_clause(qual->opType,qual->oper,
110-
lcons(find_nots((Expr*)get_leftop(qual)),
111-
lcons(find_nots((Expr*)get_rightop(qual)),
112-
NIL))));
109+
Expr*left= (Expr*)get_leftop(qual);
110+
Expr*right= (Expr*)get_rightop(qual);
111+
if (right)
112+
returnmake_clause(qual->opType,qual->oper,
113+
lcons(find_nots(left),
114+
lcons(find_nots(right),
115+
NIL)));
116+
else
117+
returnmake_clause(qual->opType,qual->oper,
118+
lcons(find_nots(left),
119+
NIL));
113120
}
114121
elseif (and_clause((Node*)qual))
115122
{
@@ -155,12 +162,17 @@ normalize(Expr *qual)
155162

156163
if (is_opclause((Node*)qual))
157164
{
158-
Expr*expr= (Expr*)qual;
159-
160-
return (make_clause(expr->opType,expr->oper,
161-
lcons(normalize((Expr*)get_leftop(qual)),
162-
lcons(normalize((Expr*)get_rightop(qual)),
163-
NIL))));
165+
Expr*left= (Expr*)get_leftop(qual);
166+
Expr*right= (Expr*)get_rightop(qual);
167+
if (right)
168+
returnmake_clause(qual->opType,qual->oper,
169+
lcons(normalize(left),
170+
lcons(normalize(right),
171+
NIL)));
172+
else
173+
returnmake_clause(qual->opType,qual->oper,
174+
lcons(normalize(left),
175+
NIL));
164176
}
165177
elseif (and_clause((Node*)qual))
166178
{
@@ -217,10 +229,17 @@ qual_cleanup(Expr *qual)
217229

218230
if (is_opclause((Node*)qual))
219231
{
220-
return ((List*)make_clause(qual->opType,qual->oper,
221-
lcons(qual_cleanup((Expr*)get_leftop(qual)),
222-
lcons(qual_cleanup((Expr*)get_rightop(qual)),
223-
NIL))));
232+
Expr*left= (Expr*)get_leftop(qual);
233+
Expr*right= (Expr*)get_rightop(qual);
234+
if (right)
235+
return (List*)make_clause(qual->opType,qual->oper,
236+
lcons(qual_cleanup(left),
237+
lcons(qual_cleanup(right),
238+
NIL)));
239+
else
240+
return (List*)make_clause(qual->opType,qual->oper,
241+
lcons(qual_cleanup(left),
242+
NIL));
224243
}
225244
elseif (and_clause((Node*)qual))
226245
{
@@ -276,10 +295,17 @@ pull_args(Expr *qual)
276295

277296
if (is_opclause((Node*)qual))
278297
{
279-
return (make_clause(qual->opType,qual->oper,
280-
lcons(pull_args((Expr*)get_leftop(qual)),
281-
lcons(pull_args((Expr*)get_rightop(qual)),
282-
NIL))));
298+
Expr*left= (Expr*)get_leftop(qual);
299+
Expr*right= (Expr*)get_rightop(qual);
300+
if (right)
301+
returnmake_clause(qual->opType,qual->oper,
302+
lcons(pull_args(left),
303+
lcons(pull_args(right),
304+
NIL)));
305+
else
306+
returnmake_clause(qual->opType,qual->oper,
307+
lcons(pull_args(left),
308+
NIL));
283309
}
284310
elseif (and_clause((Node*)qual))
285311
{
@@ -384,7 +410,7 @@ push_nots(Expr *qual)
384410
0,NULL);
385411

386412
op->op_fcache= (FunctionCache*)NULL;
387-
return(make_opclause(op,get_leftop(qual),get_rightop(qual)));
413+
returnmake_opclause(op,get_leftop(qual),get_rightop(qual));
388414
}
389415
else
390416
returnmake_notclause(qual);
@@ -511,10 +537,17 @@ remove_ands(Expr *qual)
511537
returnNIL;
512538
if (is_opclause((Node*)qual))
513539
{
514-
return ((List*)make_clause(qual->opType,qual->oper,
515-
lcons(remove_ands((Expr*)get_leftop(qual)),
516-
lcons(remove_ands((Expr*)get_rightop(qual)),
517-
NIL))));
540+
Expr*left= (Expr*)get_leftop(qual);
541+
Expr*right= (Expr*)get_rightop(qual);
542+
if (right)
543+
return (List*)make_clause(qual->opType,qual->oper,
544+
lcons(remove_ands(left),
545+
lcons(remove_ands(right),
546+
NIL)));
547+
else
548+
return (List*)make_clause(qual->opType,qual->oper,
549+
lcons(remove_ands(left),
550+
NIL));
518551
}
519552
elseif (and_clause((Node*)qual))
520553
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp