B模式下补充支持delete多表删除的delete XXX from XXXX语法
This commit is contained in:
@ -21,10 +21,16 @@ DELETE [/*+ plan_hint */] [FROM] [ ONLY ] table_name [ * ] [ [ [partition_clause
|
||||
|
||||
DELETE Multiple-Relation Syntax:
|
||||
[ WITH [ RECURSIVE ] with_query [, ...] ]
|
||||
DELETE [/*+ plan_hint */] [FROM]
|
||||
DELETE [/*+ plan_hint */] [FROM]
|
||||
{[ ONLY ] table_name [ * ] [ [ [partition_clause] [ [ AS ] alias ] ] | [ [ [ AS ] alias ] [partitions_clause] ] ]} [, ...]
|
||||
[ USING using_list ]
|
||||
[ WHERE condition | WHERE CURRENT OF cursor_name ];
|
||||
or
|
||||
[ WITH [ RECURSIVE ] with_query [, ...] ]
|
||||
DELETE [/*+ plan_hint */]
|
||||
{[ ONLY ] table_name [ * ] [ [ [partition_clause] [ [ AS ] alias ] ] | [ [ [ AS ] alias ] [partitions_clause] ] ]} [, ...]
|
||||
[ FROM using_list ]
|
||||
[ WHERE condition | WHERE CURRENT OF cursor_name ];
|
||||
|
||||
where with_query can be:
|
||||
with_query_name [ ( column_name [, ...] ) ] AS [ [ NOT ] MATERIALIZED ]
|
||||
|
||||
@ -246,6 +246,7 @@ static Node *make_node_from_scanbuf(int start_pos, int end_pos, core_yyscan_t yy
|
||||
static int64 SequenceStrGetInt64(const char *str);
|
||||
static int GetLoadType(int load_type_f, int load_type_s);
|
||||
static Node *MakeSqlLoadNode(char *colname);
|
||||
static void checkDeleteRelationError();
|
||||
|
||||
/* start with .. connect by related utilities */
|
||||
static bool IsConnectByRootIdent(Node* node);
|
||||
@ -20155,15 +20156,7 @@ DeleteStmt: opt_with_clause DELETE_P hint_string FROM relation_expr_opt_alias_li
|
||||
DeleteStmt *n = makeNode(DeleteStmt);
|
||||
n->relations = $5;
|
||||
if (list_length(n->relations) > 1) {
|
||||
#ifdef ENABLE_MULTIPLE_NODES
|
||||
ereport(errstate,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("multi-relation delete is not yet supported.")));
|
||||
#endif
|
||||
if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT)
|
||||
ereport(errstate,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("multi-relation delete only support in B-format database")));
|
||||
checkDeleteRelationError();
|
||||
}
|
||||
n->usingClause = $6;
|
||||
n->whereClause = $7;
|
||||
@ -20180,15 +20173,7 @@ DeleteStmt: opt_with_clause DELETE_P hint_string FROM relation_expr_opt_alias_li
|
||||
DeleteStmt *n = makeNode(DeleteStmt);
|
||||
n->relations = $4;
|
||||
if (list_length(n->relations) > 1) {
|
||||
#ifdef ENABLE_MULTIPLE_NODES
|
||||
ereport(errstate,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("multi-relation delete is not yet supported.")));
|
||||
#endif
|
||||
if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT)
|
||||
ereport(errstate,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("multi-relation delete only support in B-format database")));
|
||||
checkDeleteRelationError();
|
||||
}
|
||||
n->usingClause = $5;
|
||||
n->whereClause = $6;
|
||||
@ -20199,6 +20184,19 @@ DeleteStmt: opt_with_clause DELETE_P hint_string FROM relation_expr_opt_alias_li
|
||||
n->hintState = create_hintstate($3);
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
/* this is only used in multi-relation DELETE for compatibility B database. */
|
||||
| opt_with_clause DELETE_P hint_string relation_expr_opt_alias_list
|
||||
FROM from_list where_or_current_clause
|
||||
{
|
||||
DeleteStmt *n = makeNode(DeleteStmt);
|
||||
n->relations = $4;
|
||||
checkDeleteRelationError();
|
||||
n->usingClause = $6;
|
||||
n->whereClause = $7;
|
||||
n->withClause = $1;
|
||||
n->hintState = create_hintstate($3);
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
;
|
||||
|
||||
using_clause:
|
||||
@ -28543,6 +28541,19 @@ static FuncCall* MakePriorAsFunc()
|
||||
return n;
|
||||
}
|
||||
|
||||
static void checkDeleteRelationError()
|
||||
{
|
||||
#ifdef ENABLE_MULTIPLE_NODES
|
||||
ereport(errstate,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("multi-relation delete is not yet supported.")));
|
||||
#endif
|
||||
if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT)
|
||||
ereport(errstate,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("multi-relation delete only support in B-format database")));
|
||||
}
|
||||
|
||||
/*
|
||||
* Must undefine this stuff before including scan.c, since it has different
|
||||
* definitions for these macros.
|
||||
|
||||
@ -40,3 +40,7 @@ create table t_t_mutil_t1(col1 int,col2 int);
|
||||
create table t_t_mutil_t2(col1 int,col2 int);
|
||||
delete from t_t_mutil_t1 a,t_t_mutil_t2 b where a.col1=b.col1;
|
||||
ERROR: multi-relation delete only support in B-format database
|
||||
delete a from t_t_mutil_t1 a,t_t_mutil_t2 b where a.col1=b.col1;
|
||||
ERROR: multi-relation delete only support in B-format database
|
||||
delete a,b from t_t_mutil_t1 a,t_t_mutil_t2 b where a.col1=b.col1;
|
||||
ERROR: multi-relation delete only support in B-format database
|
||||
|
||||
@ -15,10 +15,16 @@ DELETE [/*+ plan_hint */] [FROM] [ ONLY ] table_name [ * ] [ [ [partition_clause
|
||||
|
||||
DELETE Multiple-Relation Syntax:
|
||||
[ WITH [ RECURSIVE ] with_query [, ...] ]
|
||||
DELETE [/*+ plan_hint */] [FROM]
|
||||
DELETE [/*+ plan_hint */] [FROM]
|
||||
{[ ONLY ] table_name [ * ] [ [ [partition_clause] [ [ AS ] alias ] ] | [ [ [ AS ] alias ] [partitions_clause] ] ]} [, ...]
|
||||
[ USING using_list ]
|
||||
[ WHERE condition | WHERE CURRENT OF cursor_name ];
|
||||
or
|
||||
[ WITH [ RECURSIVE ] with_query [, ...] ]
|
||||
DELETE [/*+ plan_hint */]
|
||||
{[ ONLY ] table_name [ * ] [ [ [partition_clause] [ [ AS ] alias ] ] | [ [ [ AS ] alias ] [partitions_clause] ] ]} [, ...]
|
||||
[ FROM using_list ]
|
||||
[ WHERE condition | WHERE CURRENT OF cursor_name ];
|
||||
|
||||
where with_query can be:
|
||||
with_query_name [ ( column_name [, ...] ) ] AS [ [ NOT ] MATERIALIZED ]
|
||||
@ -65,6 +71,38 @@ select * from t_t_mutil_t3;
|
||||
(1 row)
|
||||
|
||||
rollback;
|
||||
-- delete xx from xxx;
|
||||
begin;
|
||||
delete t_t_mutil_t1 a from t_t_mutil_t2 b,t_t_mutil_t3 c where a.col2=b.col2 and b.col2=c.col2;
|
||||
rollback;
|
||||
begin;
|
||||
delete a from t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t3 c where a.col2=b.col2 and b.col2=c.col2;
|
||||
rollback;
|
||||
begin;
|
||||
delete t_t_mutil_t1 a,t_t_mutil_t2 b from t_t_mutil_t3 c where a.col2=b.col2 and b.col2=c.col2;
|
||||
rollback;
|
||||
begin;
|
||||
delete a,b from t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t3 c where a.col2=b.col2 and b.col2=c.col2;
|
||||
rollback;
|
||||
begin;
|
||||
delete a from t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2;
|
||||
rollback;
|
||||
delete a from t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error
|
||||
ERROR: syntax error at or near "limit"
|
||||
LINE 1: ...util_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1;
|
||||
^
|
||||
delete a from t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a.col2; -- error
|
||||
ERROR: syntax error at or near "order"
|
||||
LINE 1: ...il_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a...
|
||||
^
|
||||
delete a from t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 returning *; -- error
|
||||
ERROR: syntax error at or near "returning"
|
||||
LINE 1: ...il_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 returning ...
|
||||
^
|
||||
delete t_t_mutil_t1 a from t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error
|
||||
ERROR: syntax error at or near "limit"
|
||||
LINE 1: ...util_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1;
|
||||
^
|
||||
-- condition is false
|
||||
delete from t_t_mutil_t1 a,t_t_mutil_t2 b where a.col1 = 1 and a.col1=2;
|
||||
-- different plan
|
||||
|
||||
@ -27,4 +27,6 @@ DROP TABLE delete_test;
|
||||
--multiple delete, report error except B format;
|
||||
create table t_t_mutil_t1(col1 int,col2 int);
|
||||
create table t_t_mutil_t2(col1 int,col2 int);
|
||||
delete from t_t_mutil_t1 a,t_t_mutil_t2 b where a.col1=b.col1;
|
||||
delete from t_t_mutil_t1 a,t_t_mutil_t2 b where a.col1=b.col1;
|
||||
delete a from t_t_mutil_t1 a,t_t_mutil_t2 b where a.col1=b.col1;
|
||||
delete a,b from t_t_mutil_t1 a,t_t_mutil_t2 b where a.col1=b.col1;
|
||||
@ -17,6 +17,26 @@ select * from t_t_mutil_t1;
|
||||
select * from t_t_mutil_t2;
|
||||
select * from t_t_mutil_t3;
|
||||
rollback;
|
||||
-- delete xx from xxx;
|
||||
begin;
|
||||
delete t_t_mutil_t1 a from t_t_mutil_t2 b,t_t_mutil_t3 c where a.col2=b.col2 and b.col2=c.col2;
|
||||
rollback;
|
||||
begin;
|
||||
delete a from t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t3 c where a.col2=b.col2 and b.col2=c.col2;
|
||||
rollback;
|
||||
begin;
|
||||
delete t_t_mutil_t1 a,t_t_mutil_t2 b from t_t_mutil_t3 c where a.col2=b.col2 and b.col2=c.col2;
|
||||
rollback;
|
||||
begin;
|
||||
delete a,b from t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t3 c where a.col2=b.col2 and b.col2=c.col2;
|
||||
rollback;
|
||||
begin;
|
||||
delete a from t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2;
|
||||
rollback;
|
||||
delete a from t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error
|
||||
delete a from t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a.col2; -- error
|
||||
delete a from t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 returning *; -- error
|
||||
delete t_t_mutil_t1 a from t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error
|
||||
-- condition is false
|
||||
delete from t_t_mutil_t1 a,t_t_mutil_t2 b where a.col1 = 1 and a.col1=2;
|
||||
-- different plan
|
||||
|
||||
Reference in New Issue
Block a user