Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
0b69d8a2
Commit
0b69d8a2
authored
May 09, 1999
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rearrange top-level rewrite operations so that EXPLAIN works
on queries involving UNION, EXCEPT, INTERSECT.
parent
6458daa1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
103 deletions
+122
-103
src/backend/commands/explain.c
src/backend/commands/explain.c
+11
-8
src/backend/rewrite/rewriteHandler.c
src/backend/rewrite/rewriteHandler.c
+54
-9
src/backend/tcop/postgres.c
src/backend/tcop/postgres.c
+57
-86
No files found.
src/backend/commands/explain.c
View file @
0b69d8a2
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
*
*
* Copyright (c) 1994-5, Regents of the University of California
* Copyright (c) 1994-5, Regents of the University of California
*
*
* $Id: explain.c,v 1.3
5 1999/04/25 03:19:09
tgl Exp $
* $Id: explain.c,v 1.3
6 1999/05/09 23:31:45
tgl Exp $
*
*
*/
*/
#include <stdio.h>
#include <stdio.h>
...
@@ -49,15 +49,18 @@ ExplainQuery(Query *query, bool verbose, CommandDest dest)
...
@@ -49,15 +49,18 @@ ExplainQuery(Query *query, bool verbose, CommandDest dest)
List
*
rewritten
;
List
*
rewritten
;
List
*
l
;
List
*
l
;
/* rewriter and planner may not work in aborted state? */
if
(
IsAbortedTransactionBlockState
())
if
(
IsAbortedTransactionBlockState
())
{
{
char
*
tag
=
"*ABORT STATE*"
;
EndCommand
(
tag
,
dest
);
elog
(
NOTICE
,
"(transaction aborted): %s"
,
elog
(
NOTICE
,
"(transaction aborted): %s"
,
"queries ignored until END"
);
"queries ignored until END"
);
return
;
}
/* rewriter and planner will not cope with utility statements */
if
(
query
->
commandType
==
CMD_UTILITY
)
{
elog
(
NOTICE
,
"Utility statements have no plan structure"
);
return
;
return
;
}
}
...
@@ -67,7 +70,7 @@ ExplainQuery(Query *query, bool verbose, CommandDest dest)
...
@@ -67,7 +70,7 @@ ExplainQuery(Query *query, bool verbose, CommandDest dest)
/* In the case of an INSTEAD NOTHING, tell at least that */
/* In the case of an INSTEAD NOTHING, tell at least that */
if
(
rewritten
==
NIL
)
if
(
rewritten
==
NIL
)
{
{
elog
(
NOTICE
,
"
q
uery rewrites to nothing"
);
elog
(
NOTICE
,
"
Q
uery rewrites to nothing"
);
return
;
return
;
}
}
...
@@ -88,7 +91,7 @@ ExplainOneQuery(Query *query, bool verbose, CommandDest dest)
...
@@ -88,7 +91,7 @@ ExplainOneQuery(Query *query, bool verbose, CommandDest dest)
Plan
*
plan
;
Plan
*
plan
;
ExplainState
*
es
;
ExplainState
*
es
;
/* plan the quer
ies (XXX we've ignored rewrite!!)
*/
/* plan the quer
y
*/
plan
=
planner
(
query
);
plan
=
planner
(
query
);
/* pg_plan could have failed */
/* pg_plan could have failed */
...
@@ -195,7 +198,7 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
...
@@ -195,7 +198,7 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
pname
=
"Hash"
;
pname
=
"Hash"
;
break
;
break
;
default:
default:
pname
=
""
;
pname
=
"
???
"
;
break
;
break
;
}
}
...
...
src/backend/rewrite/rewriteHandler.c
View file @
0b69d8a2
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.3
7 1999/02/22 05:26:46 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.3
8 1999/05/09 23:31:46 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -59,8 +59,6 @@ static void modifyAggrefChangeVarnodes(Node **nodePtr, int rt_index, int new_ind
...
@@ -59,8 +59,6 @@ static void modifyAggrefChangeVarnodes(Node **nodePtr, int rt_index, int new_ind
static
void
modifyAggrefDropQual
(
Node
**
nodePtr
,
Node
*
orignode
,
Expr
*
expr
);
static
void
modifyAggrefDropQual
(
Node
**
nodePtr
,
Node
*
orignode
,
Expr
*
expr
);
static
SubLink
*
modifyAggrefMakeSublink
(
Expr
*
origexp
,
Query
*
parsetree
);
static
SubLink
*
modifyAggrefMakeSublink
(
Expr
*
origexp
,
Query
*
parsetree
);
static
void
modifyAggrefQual
(
Node
**
nodePtr
,
Query
*
parsetree
);
static
void
modifyAggrefQual
(
Node
**
nodePtr
,
Query
*
parsetree
);
static
Query
*
fireRIRrules
(
Query
*
parsetree
);
static
Query
*
fireRIRrules
(
Query
*
parsetree
);
...
@@ -2634,12 +2632,12 @@ RewritePreprocessQuery(Query *parsetree)
...
@@ -2634,12 +2632,12 @@ RewritePreprocessQuery(Query *parsetree)
/*
/*
* QueryRewrite -
*
Basic
QueryRewrite -
* rewrite one query via query rewrite system, possibly returning 0
* rewrite one query via query rewrite system, possibly returning 0
* or many queries
* or many queries
*/
*/
List
*
static
List
*
QueryRewrite
(
Query
*
parsetree
)
Basic
QueryRewrite
(
Query
*
parsetree
)
{
{
List
*
querylist
;
List
*
querylist
;
List
*
results
=
NIL
;
List
*
results
=
NIL
;
...
@@ -2672,10 +2670,57 @@ QueryRewrite(Query *parsetree)
...
@@ -2672,10 +2670,57 @@ QueryRewrite(Query *parsetree)
}
}
return
results
;
return
results
;
}
}
/***S*I***/
/* This function takes two targetlists as arguments and checks if the targetlists are compatible
/*
* (i.e. both select for the same number of attributes and the types are compatible
* QueryRewrite -
* Primary entry point to the query rewriter.
* Rewrite one query via query rewrite system, possibly returning 0
* or many queries.
*
* NOTE: The code in QueryRewrite was formerly in pg_parse_and_plan(), and was
* moved here so that it would be invoked during EXPLAIN. The division of
* labor between this routine and BasicQueryRewrite is not obviously correct
* ... at least not to me ... tgl 5/99.
*/
List
*
QueryRewrite
(
Query
*
parsetree
)
{
List
*
rewritten
,
*
rewritten_item
;
/***S*I***/
/* Rewrite Union, Intersect and Except Queries
* to normal Union Queries using IN and NOT IN subselects */
if
(
parsetree
->
intersectClause
)
parsetree
=
Except_Intersect_Rewrite
(
parsetree
);
/* Rewrite basic queries (retrieve, append, delete, replace) */
rewritten
=
BasicQueryRewrite
(
parsetree
);
/*
* Rewrite the UNIONS.
*/
*/
foreach
(
rewritten_item
,
rewritten
)
{
Query
*
qry
=
(
Query
*
)
lfirst
(
rewritten_item
);
List
*
union_result
=
NIL
;
List
*
union_item
;
foreach
(
union_item
,
qry
->
unionClause
)
{
union_result
=
nconc
(
union_result
,
BasicQueryRewrite
((
Query
*
)
lfirst
(
union_item
)));
}
qry
->
unionClause
=
union_result
;
}
return
rewritten
;
}
/***S*I***/
/* This function takes two targetlists as arguments and checks if the
* targetlists are compatible (i.e. both select for the same number of
* attributes and the types are compatible */
void
check_targetlists_are_compatible
(
List
*
prev_target
,
List
*
current_target
)
void
check_targetlists_are_compatible
(
List
*
prev_target
,
List
*
current_target
)
{
{
List
*
next_target
;
List
*
next_target
;
...
...
src/backend/tcop/postgres.c
View file @
0b69d8a2
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.11
0 1999/05/03 19:09:54 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.11
1 1999/05/09 23:31:47 tgl
Exp $
*
*
* NOTES
* NOTES
* this is the "main" module of the postgres backend and
* this is the "main" module of the postgres backend and
...
@@ -399,49 +399,6 @@ pg_parse_and_plan(char *query_string, /* string to execute */
...
@@ -399,49 +399,6 @@ pg_parse_and_plan(char *query_string, /* string to execute */
List
*
rewritten
=
NIL
;
List
*
rewritten
=
NIL
;
Query
*
querytree
;
Query
*
querytree
;
/* ----------------
* (1) parse the request string into a list of parse trees
* ----------------
*/
if
(
ShowParserStats
)
ResetUsage
();
querytree_list
=
parser
(
query_string
,
typev
,
nargs
);
if
(
ShowParserStats
)
{
fprintf
(
stderr
,
"! Parser Stats:
\n
"
);
ShowUsage
();
}
/* new_list holds the rewritten queries */
new_list
=
(
QueryTreeList
*
)
malloc
(
sizeof
(
QueryTreeList
));
new_list
->
len
=
querytree_list
->
len
;
new_list
->
qtrees
=
(
Query
**
)
malloc
(
new_list
->
len
*
sizeof
(
Query
*
));
/* ----------------
* (2) rewrite the queries, as necessary
* ----------------
*/
j
=
0
;
/* counter for the new_list, new_list can
* be longer than old list as a result of
* rewrites */
for
(
i
=
0
;
i
<
querytree_list
->
len
;
i
++
)
{
List
*
union_result
,
*
union_list
,
*
rewritten_list
;
querytree
=
querytree_list
->
qtrees
[
i
];
/***S*I***/
/* Rewrite Union, Intersect and Except Queries
* to normal Union Queries using IN and NOT IN subselects */
if
(
querytree
->
intersectClause
!=
NIL
)
{
querytree
=
Except_Intersect_Rewrite
(
querytree
);
}
if
(
DebugPrintQuery
)
if
(
DebugPrintQuery
)
{
{
if
(
DebugPrintQuery
>
3
)
if
(
DebugPrintQuery
>
3
)
...
@@ -485,20 +442,52 @@ pg_parse_and_plan(char *query_string, /* string to execute */
...
@@ -485,20 +442,52 @@ pg_parse_and_plan(char *query_string, /* string to execute */
}
}
}
}
/* don't rewrite utilites */
/* ----------------
if
(
querytree
->
commandType
==
CMD_UTILITY
)
* (1) parse the request string into a list of parse trees
* ----------------
*/
if
(
ShowParserStats
)
ResetUsage
();
querytree_list
=
parser
(
query_string
,
typev
,
nargs
);
if
(
ShowParserStats
)
{
{
new_list
->
qtrees
[
j
++
]
=
querytree
;
fprintf
(
stderr
,
"! Parser Stats:
\n
"
)
;
continue
;
ShowUsage
()
;
}
}
/* new_list holds the rewritten queries */
new_list
=
(
QueryTreeList
*
)
malloc
(
sizeof
(
QueryTreeList
));
new_list
->
len
=
querytree_list
->
len
;
new_list
->
qtrees
=
(
Query
**
)
malloc
(
new_list
->
len
*
sizeof
(
Query
*
));
/* ----------------
* (2) rewrite the queries, as necessary
*
* j counts queries output into new_list; the number of rewritten
* queries can be different from the original number.
* ----------------
*/
j
=
0
;
for
(
i
=
0
;
i
<
querytree_list
->
len
;
i
++
)
{
querytree
=
querytree_list
->
qtrees
[
i
];
if
(
DebugPrintParse
)
if
(
DebugPrintParse
)
{
{
TPRINTF
(
TRACE_PARSE
,
"parser outputs:"
);
TPRINTF
(
TRACE_PARSE
,
"parser outputs:"
);
nodeDisplay
(
querytree
);
nodeDisplay
(
querytree
);
}
}
/* rewrite queries (retrieve, append, delete, replace) */
/* don't rewrite utilites, just dump 'em into new_list */
if
(
querytree
->
commandType
==
CMD_UTILITY
)
{
new_list
->
qtrees
[
j
++
]
=
querytree
;
continue
;
}
/* rewrite regular queries */
rewritten
=
QueryRewrite
(
querytree
);
rewritten
=
QueryRewrite
(
querytree
);
if
(
rewritten
!=
NIL
)
if
(
rewritten
!=
NIL
)
...
@@ -506,19 +495,6 @@ pg_parse_and_plan(char *query_string, /* string to execute */
...
@@ -506,19 +495,6 @@ pg_parse_and_plan(char *query_string, /* string to execute */
int
len
,
int
len
,
k
;
k
;
/*
* Rewrite the UNIONS.
*/
foreach
(
rewritten_list
,
rewritten
)
{
Query
*
qry
=
(
Query
*
)
lfirst
(
rewritten_list
);
union_result
=
NIL
;
foreach
(
union_list
,
qry
->
unionClause
)
union_result
=
nconc
(
union_result
,
QueryRewrite
((
Query
*
)
lfirst
(
union_list
)));
qry
->
unionClause
=
union_result
;
}
len
=
length
(
rewritten
);
len
=
length
(
rewritten
);
if
(
len
==
1
)
if
(
len
==
1
)
new_list
->
qtrees
[
j
++
]
=
(
Query
*
)
lfirst
(
rewritten
);
new_list
->
qtrees
[
j
++
]
=
(
Query
*
)
lfirst
(
rewritten
);
...
@@ -537,12 +513,7 @@ pg_parse_and_plan(char *query_string, /* string to execute */
...
@@ -537,12 +513,7 @@ pg_parse_and_plan(char *query_string, /* string to execute */
}
}
}
}
/* ----------
/* Update new_list with correct final length */
* Due to rewriting, the new list could also have been
* shrunk (do instead nothing). Forget obsolete queries
* at the end.
* ----------
*/
new_list
->
len
=
j
;
new_list
->
len
=
j
;
/* we're done with the original lists, free it */
/* we're done with the original lists, free it */
...
@@ -657,7 +628,7 @@ pg_parse_and_plan(char *query_string, /* string to execute */
...
@@ -657,7 +628,7 @@ pg_parse_and_plan(char *query_string, /* string to execute */
}
}
/* ----------
/* ----------
* Check if the rewriting had thrown away
an
ything
* Check if the rewriting had thrown away
ever
ything
* ----------
* ----------
*/
*/
if
(
querytree_list
->
len
==
0
)
if
(
querytree_list
->
len
==
0
)
...
@@ -1539,7 +1510,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
...
@@ -1539,7 +1510,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if
(
!
IsUnderPostmaster
)
if
(
!
IsUnderPostmaster
)
{
{
puts
(
"
\n
POSTGRES backend interactive interface "
);
puts
(
"
\n
POSTGRES backend interactive interface "
);
puts
(
"$Revision: 1.11
0 $ $Date: 1999/05/03 19:09:54
$
\n
"
);
puts
(
"$Revision: 1.11
1 $ $Date: 1999/05/09 23:31:47
$
\n
"
);
}
}
/* ----------------
/* ----------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment