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

Commit51f62ea

Browse files
committed
Rule deparser didn't handle unary operators correctly.
1 parent68c3234 commit51f62ea

File tree

1 file changed

+74
-22
lines changed

1 file changed

+74
-22
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* out of it's tuple
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.24 1999/08/28 03:59:05 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.25 1999/09/02 03:04:04 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -43,8 +43,9 @@
4343
#include"optimizer/clauses.h"
4444
#include"optimizer/tlist.h"
4545
#include"utils/lsyscache.h"
46-
#include"catalog/pg_shadow.h"
4746
#include"catalog/pg_index.h"
47+
#include"catalog/pg_operator.h"
48+
#include"catalog/pg_shadow.h"
4849

4950
#defineBUFSIZE 8192
5051

@@ -1270,6 +1271,7 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix)
12701271
caseT_Expr:
12711272
{
12721273
Expr*expr= (Expr*)node;
1274+
List*args=expr->args;
12731275

12741276
/* ----------
12751277
* Expr nodes have to be handled a bit detailed
@@ -1279,41 +1281,91 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix)
12791281
{
12801282
caseOP_EXPR:
12811283
strcat(buf,"(");
1282-
strcat(buf,get_rule_expr(qh,rt_index,
1283-
(Node*)get_leftop(expr),
1284-
varprefix));
1285-
strcat(buf," ");
1286-
strcat(buf,get_opname(((Oper*)expr->oper)->opno));
1287-
strcat(buf," ");
1288-
strcat(buf,get_rule_expr(qh,rt_index,
1289-
(Node*)get_rightop(expr),
1290-
varprefix));
1284+
if (length(args)==2)
1285+
{
1286+
/* binary operator */
1287+
strcat(buf,
1288+
get_rule_expr(qh,rt_index,
1289+
(Node*)lfirst(args),
1290+
varprefix));
1291+
strcat(buf," ");
1292+
strcat(buf,
1293+
get_opname(((Oper*)expr->oper)->opno));
1294+
strcat(buf," ");
1295+
strcat(buf,
1296+
get_rule_expr(qh,rt_index,
1297+
(Node*)lsecond(args),
1298+
varprefix));
1299+
}
1300+
else
1301+
{
1302+
/* unary operator --- but which side? */
1303+
Oidopno= ((Oper*)expr->oper)->opno;
1304+
HeapTupletp;
1305+
Form_pg_operatoroptup;
1306+
1307+
tp=SearchSysCacheTuple(OPROID,
1308+
ObjectIdGetDatum(opno),
1309+
0,0,0);
1310+
Assert(HeapTupleIsValid(tp));
1311+
optup= (Form_pg_operator)GETSTRUCT(tp);
1312+
switch (optup->oprkind)
1313+
{
1314+
case'l':
1315+
strcat(buf,get_opname(opno));
1316+
strcat(buf," ");
1317+
strcat(buf,
1318+
get_rule_expr(qh,rt_index,
1319+
(Node*)lfirst(args),
1320+
varprefix));
1321+
break;
1322+
case'r':
1323+
strcat(buf,
1324+
get_rule_expr(qh,rt_index,
1325+
(Node*)lfirst(args),
1326+
varprefix));
1327+
strcat(buf," ");
1328+
strcat(buf,get_opname(opno));
1329+
break;
1330+
default:
1331+
elog(ERROR,"get_rule_expr: bogus oprkind");
1332+
}
1333+
}
12911334
strcat(buf,")");
12921335
returnpstrdup(buf);
12931336
break;
12941337

12951338
caseOR_EXPR:
12961339
strcat(buf,"(");
12971340
strcat(buf,get_rule_expr(qh,rt_index,
1298-
(Node*)get_leftop(expr),
1299-
varprefix));
1300-
strcat(buf," OR ");
1301-
strcat(buf,get_rule_expr(qh,rt_index,
1302-
(Node*)get_rightop(expr),
1341+
(Node*)lfirst(args),
13031342
varprefix));
1343+
/* It's not clear that we can ever see N-argument
1344+
* OR/AND clauses here, but might as well cope...
1345+
*/
1346+
while ((args=lnext(args))!=NIL)
1347+
{
1348+
strcat(buf," OR ");
1349+
strcat(buf,get_rule_expr(qh,rt_index,
1350+
(Node*)lfirst(args),
1351+
varprefix));
1352+
}
13041353
strcat(buf,")");
13051354
returnpstrdup(buf);
13061355
break;
13071356

13081357
caseAND_EXPR:
13091358
strcat(buf,"(");
13101359
strcat(buf,get_rule_expr(qh,rt_index,
1311-
(Node*)get_leftop(expr),
1312-
varprefix));
1313-
strcat(buf," AND ");
1314-
strcat(buf,get_rule_expr(qh,rt_index,
1315-
(Node*)get_rightop(expr),
1360+
(Node*)lfirst(args),
13161361
varprefix));
1362+
while ((args=lnext(args))!=NIL)
1363+
{
1364+
strcat(buf," AND ");
1365+
strcat(buf,get_rule_expr(qh,rt_index,
1366+
(Node*)lfirst(args),
1367+
varprefix));
1368+
}
13171369
strcat(buf,")");
13181370
returnpstrdup(buf);
13191371
break;
@@ -1335,7 +1387,7 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix)
13351387

13361388
default:
13371389
printf("\n%s\n",nodeToString(node));
1338-
elog(ERROR,"Expr type not supported");
1390+
elog(ERROR,"get_rule_expr: expr type not supported");
13391391
}
13401392
}
13411393
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp