Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
0b69d8a2
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0b69d8a2
编写于
5月 09, 1999
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rearrange top-level rewrite operations so that EXPLAIN works
on queries involving UNION, EXCEPT, INTERSECT.
上级
6458daa1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
122 addition
and
103 deletion
+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
未找到文件。
src/backend/commands/explain.c
浏览文件 @
0b69d8a2
...
...
@@ -4,7 +4,7 @@
*
* 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>
...
...
@@ -49,15 +49,18 @@ ExplainQuery(Query *query, bool verbose, CommandDest dest)
List
*
rewritten
;
List
*
l
;
/* rewriter and planner may not work in aborted state? */
if
(
IsAbortedTransactionBlockState
())
{
char
*
tag
=
"*ABORT STATE*"
;
EndCommand
(
tag
,
dest
);
elog
(
NOTICE
,
"(transaction aborted): %s"
,
"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
;
}
...
...
@@ -67,7 +70,7 @@ ExplainQuery(Query *query, bool verbose, CommandDest dest)
/* In the case of an INSTEAD NOTHING, tell at least that */
if
(
rewritten
==
NIL
)
{
elog
(
NOTICE
,
"
q
uery rewrites to nothing"
);
elog
(
NOTICE
,
"
Q
uery rewrites to nothing"
);
return
;
}
...
...
@@ -88,7 +91,7 @@ ExplainOneQuery(Query *query, bool verbose, CommandDest dest)
Plan
*
plan
;
ExplainState
*
es
;
/* plan the quer
ies (XXX we've ignored rewrite!!)
*/
/* plan the quer
y
*/
plan
=
planner
(
query
);
/* pg_plan could have failed */
...
...
@@ -195,7 +198,7 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
pname
=
"Hash"
;
break
;
default:
pname
=
""
;
pname
=
"
???
"
;
break
;
}
...
...
src/backend/rewrite/rewriteHandler.c
浏览文件 @
0b69d8a2
...
...
@@ -6,7 +6,7 @@
*
*
* 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
static
void
modifyAggrefDropQual
(
Node
**
nodePtr
,
Node
*
orignode
,
Expr
*
expr
);
static
SubLink
*
modifyAggrefMakeSublink
(
Expr
*
origexp
,
Query
*
parsetree
);
static
void
modifyAggrefQual
(
Node
**
nodePtr
,
Query
*
parsetree
);
static
Query
*
fireRIRrules
(
Query
*
parsetree
);
...
...
@@ -2634,12 +2632,12 @@ RewritePreprocessQuery(Query *parsetree)
/*
* QueryRewrite -
*
Basic
QueryRewrite -
* rewrite one query via query rewrite system, possibly returning 0
* or many queries
*/
List
*
QueryRewrite
(
Query
*
parsetree
)
static
List
*
Basic
QueryRewrite
(
Query
*
parsetree
)
{
List
*
querylist
;
List
*
results
=
NIL
;
...
...
@@ -2672,10 +2670,57 @@ QueryRewrite(Query *parsetree)
}
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
)
{
List
*
next_target
;
...
...
src/backend/tcop/postgres.c
浏览文件 @
0b69d8a2
...
...
@@ -7,7 +7,7 @@
*
*
* 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
* this is the "main" module of the postgres backend and
...
...
@@ -399,6 +399,49 @@ pg_parse_and_plan(char *query_string, /* string to execute */
List
*
rewritten
=
NIL
;
Query
*
querytree
;
if
(
DebugPrintQuery
)
{
if
(
DebugPrintQuery
>
3
)
{
/* Print the query string as is if query debug level > 3 */
TPRINTF
(
TRACE_QUERY
,
"query: %s"
,
query_string
);
}
else
{
/* Print condensed query string to fit in one log line */
char
buff
[
MAX_QUERY_SIZE
+
1
];
char
c
,
*
s
,
*
d
;
int
n
,
is_space
=
1
;
for
(
s
=
query_string
,
d
=
buff
,
n
=
0
;
(
c
=
*
s
)
&&
(
n
<
MAX_QUERY_SIZE
);
s
++
)
{
switch
(
c
)
{
case
'\r'
:
case
'\n'
:
case
'\t'
:
c
=
' '
;
/* fall through */
case
' '
:
if
(
is_space
)
continue
;
is_space
=
1
;
break
;
default:
is_space
=
0
;
break
;
}
*
d
++
=
c
;
n
++
;
}
*
d
=
'\0'
;
TPRINTF
(
TRACE_QUERY
,
"query: %s"
,
buff
);
}
}
/* ----------------
* (1) parse the request string into a list of parse trees
* ----------------
...
...
@@ -421,84 +464,30 @@ pg_parse_and_plan(char *query_string, /* string to execute */
/* ----------------
* (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
;
/* counter for the new_list, new_list can
* be longer than old list as a result of
* rewrites */
j
=
0
;
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
(
DebugPrintParse
)
{
if
(
DebugPrintQuery
>
3
)
{
/* Print the query string as is if query debug level > 3 */
TPRINTF
(
TRACE_QUERY
,
"query: %s"
,
query_string
);
}
else
{
/* Print condensed query string to fit in one log line */
char
buff
[
MAX_QUERY_SIZE
+
1
];
char
c
,
*
s
,
*
d
;
int
n
,
is_space
=
1
;
for
(
s
=
query_string
,
d
=
buff
,
n
=
0
;
(
c
=
*
s
)
&&
(
n
<
MAX_QUERY_SIZE
);
s
++
)
{
switch
(
c
)
{
case
'\r'
:
case
'\n'
:
case
'\t'
:
c
=
' '
;
/* fall through */
case
' '
:
if
(
is_space
)
continue
;
is_space
=
1
;
break
;
default:
is_space
=
0
;
break
;
}
*
d
++
=
c
;
n
++
;
}
*
d
=
'\0'
;
TPRINTF
(
TRACE_QUERY
,
"query: %s"
,
buff
);
}
TPRINTF
(
TRACE_PARSE
,
"parser outputs:"
);
nodeDisplay
(
querytree
);
}
/* don't rewrite utilites */
/* don't rewrite utilites
, just dump 'em into new_list
*/
if
(
querytree
->
commandType
==
CMD_UTILITY
)
{
new_list
->
qtrees
[
j
++
]
=
querytree
;
continue
;
}
if
(
DebugPrintParse
)
{
TPRINTF
(
TRACE_PARSE
,
"parser outputs:"
);
nodeDisplay
(
querytree
);
}
/* rewrite queries (retrieve, append, delete, replace) */
/* rewrite regular queries */
rewritten
=
QueryRewrite
(
querytree
);
if
(
rewritten
!=
NIL
)
...
...
@@ -506,19 +495,6 @@ pg_parse_and_plan(char *query_string, /* string to execute */
int
len
,
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
);
if
(
len
==
1
)
new_list
->
qtrees
[
j
++
]
=
(
Query
*
)
lfirst
(
rewritten
);
...
...
@@ -530,19 +506,14 @@ pg_parse_and_plan(char *query_string, /* string to execute */
* we allocated one space
* for the query */
new_list
->
qtrees
=
realloc
(
new_list
->
qtrees
,
new_list
->
len
*
sizeof
(
Query
*
));
new_list
->
len
*
sizeof
(
Query
*
));
for
(
k
=
0
;
k
<
len
;
k
++
)
new_list
->
qtrees
[
j
++
]
=
(
Query
*
)
nth
(
k
,
rewritten
);
}
}
}
/* ----------
* Due to rewriting, the new list could also have been
* shrunk (do instead nothing). Forget obsolete queries
* at the end.
* ----------
*/
/* Update new_list with correct final length */
new_list
->
len
=
j
;
/* we're done with the original lists, free it */
...
...
@@ -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
)
...
...
@@ -1539,7 +1510,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if
(
!
IsUnderPostmaster
)
{
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
"
);
}
/* ----------------
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录