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

Commit8487628

Browse files
committed
Cast constants to the type of the other binary operand.
Invalidate vacuum relation cache to use new row counts from vacuum.
1 parenta4ee68d commit8487628

File tree

10 files changed

+105
-26
lines changed

10 files changed

+105
-26
lines changed

‎src/backend/commands/vacuum.c

Lines changed: 8 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/commands/vacuum.c,v 1.14 1997/01/13 03:43:59 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.15 1997/01/22 01:42:16 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -29,10 +29,12 @@
2929
#include<catalog/pg_index.h>
3030
#include<catalog/index.h>
3131
#include<catalog/catname.h>
32+
#include<catalog/catalog.h>
3233
#include<catalog/pg_class.h>
3334
#include<catalog/pg_proc.h>
3435
#include<storage/smgr.h>
3536
#include<storage/lmgr.h>
37+
#include<utils/inval.h>
3638
#include<utils/mcxt.h>
3739
#include<utils/syscache.h>
3840
#include<commands/vacuum.h>
@@ -1430,6 +1432,11 @@ _vc_updstats(Oid relid, int npages, int ntuples, bool hasindex)
14301432
/* XXX -- after write, should invalidate relcache in other backends */
14311433
WriteNoReleaseBuffer(buf);/* heap_endscan release scan' buffers ? */
14321434

1435+
/* invalidating system relations confuses the function cache
1436+
of pg_operator and pg_opclass */
1437+
if ( !IsSystemRelationName(pgcform->relname.data))
1438+
RelationInvalidateHeapTuple(rd,tup);
1439+
14331440
/* that's all, folks */
14341441
heap_endscan(sdesc);
14351442
heap_close(rd);

‎src/backend/nodes/makefuncs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.1.1.1 1996/07/09 06:21:32 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.2 1997/01/22 01:42:26 momjian Exp $
1111
*
1212
* NOTES
1313
* Creator functions in POSTGRES 4.2 are generated automatically. Most of
@@ -102,7 +102,8 @@ makeConst(Oid consttype,
102102
Datumconstvalue,
103103
boolconstisnull,
104104
boolconstbyval,
105-
boolconstisset)
105+
boolconstisset,
106+
boolconstiscast)
106107
{
107108
Const*cnst=makeNode(Const);
108109

@@ -112,6 +113,7 @@ makeConst(Oid consttype,
112113
cnst->constisnull=constisnull;
113114
cnst->constbyval=constbyval;
114115
cnst->constisset=constisset;
116+
cnst->constiscast=constiscast;
115117
returncnst;
116118
}
117119

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

Lines changed: 3 additions & 2 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/preptlist.c,v 1.1.1.1 1996/07/09 06:21:38scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.2 1997/01/22 01:42:38momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -279,7 +279,8 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type)
279279
(typedefault== (structvarlena*)NULL),
280280
/* XXX this is bullshit */
281281
false,
282-
false/* not a set */);
282+
false,/* not a set */
283+
false);
283284

284285
temp3=MakeTLE (makeResdom(attno,
285286
atttype,

‎src/backend/parser/analyze.c

Lines changed: 5 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/parser/analyze.c,v 1.19 1996/12/17 01:53:26 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.20 1997/01/22 01:42:54 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1288,7 +1288,8 @@ make_targetlist_expr(ParseState *pstate,
12881288
val,
12891289
false,
12901290
true,
1291-
true/* is set */);
1291+
true,/* is set */
1292+
false);
12921293
}else {
12931294
lnext(expr)=
12941295
makeConst(attrtype,
@@ -1297,7 +1298,8 @@ make_targetlist_expr(ParseState *pstate,
12971298
val,get_typelem(attrtype),-1),
12981299
false,
12991300
true/* Maybe correct-- 80% chance */,
1300-
false/* is not a set */);
1301+
false,/* is not a set */
1302+
false);
13011303
}
13021304
}elseif((Typecast_ok)&& (attrtype!=type_id)){
13031305
lnext(expr)=

‎src/backend/parser/catalog_utils.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/catalog_utils.c,v 1.14 1996/12/26 17:47:41 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/catalog_utils.c,v 1.15 1997/01/22 01:43:08 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -1405,6 +1405,26 @@ typeid_get_retinfunc(Oid type_id)
14051405
return(infunc);
14061406
}
14071407

1408+
/* Given a type id, returns the out-conversion function of the type */
1409+
Oid
1410+
typeid_get_retoutfunc(Oidtype_id)
1411+
{
1412+
HeapTupletypeTuple;
1413+
TypeTupleFormtype;
1414+
Oidoutfunc;
1415+
typeTuple=SearchSysCacheTuple(TYPOID,
1416+
ObjectIdGetDatum(type_id),
1417+
0,0,0);
1418+
if ( !HeapTupleIsValid (typeTuple ))
1419+
elog(WARN,
1420+
"typeid_get_retoutfunc: Invalid type - oid = %u",
1421+
type_id);
1422+
1423+
type= (TypeTupleForm)GETSTRUCT(typeTuple);
1424+
outfunc=type->typoutput;
1425+
return(outfunc);
1426+
}
1427+
14081428
Oid
14091429
typeid_get_relid(Oidtype_id)
14101430
{

‎src/backend/parser/parse_query.c

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/parse_query.c,v 1.11 1996/12/07 04:38:10 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/parse_query.c,v 1.12 1997/01/22 01:43:19 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -367,10 +367,50 @@ make_op(char *opname, Node *ltree, Node *rtree)
367367
left=NULL;
368368

369369
}else {
370-
370+
char*outstr;
371+
Oidinfunc,outfunc;
372+
Typenewtype;
373+
374+
#defineCONVERTABLE_TYPE(t) ((t) == INT2OID || \
375+
(t) == INT4OID || \
376+
(t) == OIDOID || \
377+
(t) == FLOAT4OID || \
378+
(t) == FLOAT8OID)
379+
371380
/* binary operator */
372381
ltypeId= (ltree==NULL) ?UNKNOWNOID :exprType(ltree);
373382
rtypeId= (rtree==NULL) ?UNKNOWNOID :exprType(rtree);
383+
384+
/* convert constant when using a const of a numeric type
385+
and a non-const of another numeric type */
386+
if (CONVERTABLE_TYPE(ltypeId)&&nodeTag(ltree)!=T_Const&&
387+
CONVERTABLE_TYPE(rtypeId)&&nodeTag(rtree)==T_Const&&
388+
!((Const*)rtree)->constiscast) {
389+
outfunc=typeid_get_retoutfunc(rtypeId);
390+
infunc=typeid_get_retinfunc(ltypeId);
391+
outstr= (char*)fmgr(outfunc, ((Const*)rtree)->constvalue);
392+
((Const*)rtree)->constvalue= (Datum)fmgr(infunc,outstr);
393+
pfree(outstr);
394+
((Const*)rtree)->consttype=rtypeId=ltypeId;
395+
newtype=get_id_type(rtypeId);
396+
((Const*)rtree)->constlen=tlen(newtype);
397+
((Const*)rtree)->constbyval=tbyval(newtype);
398+
}
399+
400+
if (CONVERTABLE_TYPE(rtypeId)&&nodeTag(rtree)!=T_Const&&
401+
CONVERTABLE_TYPE(ltypeId)&&nodeTag(ltree)==T_Const&&
402+
!((Const*)ltree)->constiscast) {
403+
outfunc=typeid_get_retoutfunc(ltypeId);
404+
infunc=typeid_get_retinfunc(rtypeId);
405+
outstr= (char*)fmgr(outfunc, ((Const*)ltree)->constvalue);
406+
((Const*)ltree)->constvalue= (Datum)fmgr(infunc,outstr);
407+
pfree(outstr);
408+
((Const*)ltree)->consttype=ltypeId=rtypeId;
409+
newtype=get_id_type(ltypeId);
410+
((Const*)ltree)->constlen=tlen(newtype);
411+
((Const*)ltree)->constbyval=tbyval(newtype);
412+
}
413+
374414
temp=oper(opname,ltypeId,rtypeId);
375415
opform= (OperatorTupleForm)GETSTRUCT(temp);
376416
left=make_operand(opname,ltree,ltypeId,opform->oprleft);
@@ -654,17 +694,18 @@ make_const(Value *value)
654694
elog(NOTICE,"unknown type : %d\n",nodeTag(value));
655695

656696
/* null const */
657-
con=makeConst(0,0, (Datum)NULL,TRUE,0, FALSE);
697+
con=makeConst(0,0, (Datum)NULL,true, false, false, false);
658698
returncon;
659699
}
660700
}
661701

662702
con=makeConst(typeid(tp),
663703
tlen(tp),
664704
val,
665-
FALSE,
705+
false,
666706
tbyval(tp),
667-
FALSE);/* not a set */
707+
false,/* not a set */
708+
false);
668709

669710
return (con);
670711
}

‎src/backend/parser/parser.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.16 1996/12/26 17:47:42 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.17 1997/01/22 01:43:26 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -283,9 +283,10 @@ parser_typecast(Value *expr, TypeName *typename, int typlen)
283283
adt=makeConst(typeid(tp),
284284
len,
285285
(Datum)lcp ,
286-
0,
286+
false,
287287
tbyvalue(tp),
288-
0/* not a set */);
288+
false,/* not a set */
289+
true/* is cast */);
289290

290291
if (string_palloced)
291292
pfree(const_string);
@@ -365,8 +366,9 @@ parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
365366
(Size)0,
366367
(Datum)NULL,
367368
true,/* isnull */
368-
0/* was omitted */,
369-
0/* not a set */);
369+
false,/* was omitted */
370+
false,/* not a set */
371+
true/* is cast */);
370372
return ((Node*)adt);
371373
}
372374

@@ -401,9 +403,10 @@ parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
401403
adt=makeConst(typeid(tp),
402404
(Size)len,
403405
(Datum)lcp,
404-
0,
405-
0/*was omitted*/,
406-
0/* not a set */);
406+
false,
407+
false,/*was omitted*/
408+
false,/* not a set */
409+
true/* is cast */);
407410
/*
408411
printf("adt %s : %u %d %d\n",CString(expr),typeid(tp) ,
409412
len,cp);

‎src/include/nodes/makefuncs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: makefuncs.h,v 1.2 1996/11/06 09:21:42 scrappy Exp $
9+
* $Id: makefuncs.h,v 1.3 1997/01/22 01:43:41 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -41,6 +41,7 @@ extern Const *makeConst(Oid consttype,
4141
Datumconstvalue,
4242
boolconstisnull,
4343
boolconstbyval,
44-
boolconstisset);
44+
boolconstisset,
45+
boolconstiscast);
4546

4647
#endif/* MAKEFUNC_H */

‎src/include/nodes/primnodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: primnodes.h,v 1.6 1996/11/04 07:18:21 scrappy Exp $
9+
* $Id: primnodes.h,v 1.7 1997/01/22 01:43:44 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -175,6 +175,7 @@ typedef struct Const {
175175
boolconstisnull;
176176
boolconstbyval;
177177
boolconstisset;
178+
boolconstiscast;
178179
}Const;
179180

180181
/* ----------------

‎src/include/parser/catalog_utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: catalog_utils.h,v 1.6 1996/12/11 03:18:12 bryanh Exp $
9+
* $Id: catalog_utils.h,v 1.7 1997/01/22 01:44:02 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -46,6 +46,7 @@ extern Oid funcid_get_rettype(Oid funcid);
4646
externboolfunc_get_detail(char*funcname,intnargs,Oid*oid_array,
4747
Oid*funcid,Oid*rettype,bool*retset,Oid**true_typeids);
4848
externOidtypeid_get_retinfunc(Oidtype_id);
49+
externOidtypeid_get_retoutfunc(Oidtype_id);
4950
externOidtypeid_get_relid(Oidtype_id);
5051
externOidget_typrelid(Typetyp);
5152
externOidget_typelem(Oidtype_id);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp