MCPcopy Create free account
hub / github.com/apache/cloudberry / transformDeleteStmt

Function transformDeleteStmt

src/backend/parser/analyze.c:539–619  ·  view source on GitHub ↗

* transformDeleteStmt - * transforms a Delete Statement */

Source from the content-addressed store, hash-verified

537 * transforms a Delete Statement
538 */
539static Query *
540transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt)
541{
542 Query *qry = makeNode(Query);
543 ParseNamespaceItem *nsitem;
544 Node *qual;
545
546 qry->commandType = CMD_DELETE;
547
548 /* process the WITH clause independently of all else */
549 if (stmt->withClause)
550 {
551 qry->hasRecursive = stmt->withClause->recursive;
552 qry->cteList = transformWithClause(pstate, stmt->withClause);
553 qry->hasModifyingCTE = pstate->p_hasModifyingCTE;
554
555 /*
556 * Since GPDB currently only support a single writer gang, only one
557 * writable clause is permitted per CTE. Once we get flexible gangs
558 * with more than one writer gang we can lift this restriction.
559 */
560 if (pstate->p_hasModifyingCTE)
561 ereport(ERROR,
562 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
563 errmsg("writable CTE queries cannot be themselves writable"),
564 errdetail("Apache Cloudberry currently only support CTEs with one writable clause, called in a non-writable context."),
565 errhint("Rewrite the query to only include one writable clause.")));
566 }
567
568 /* set up range table with just the result rel */
569 qry->resultRelation = setTargetTable(pstate, stmt->relation,
570 stmt->relation->inh,
571 true,
572 ACL_DELETE);
573 nsitem = pstate->p_target_nsitem;
574
575 /* there's no DISTINCT in DELETE */
576 qry->distinctClause = NIL;
577
578 /* subqueries in USING cannot access the result relation */
579 nsitem->p_lateral_only = true;
580 nsitem->p_lateral_ok = false;
581
582 /*
583 * The USING clause is non-standard SQL syntax, and is equivalent in
584 * functionality to the FROM list that can be specified for UPDATE. The
585 * USING keyword is used rather than FROM because FROM is already a
586 * keyword in the DELETE syntax.
587 */
588 transformFromClause(pstate, stmt->usingClause);
589
590 /* remaining clauses can reference the result relation normally */
591 nsitem->p_lateral_only = false;
592 nsitem->p_lateral_ok = true;
593
594 qual = transformWhereClause(pstate, stmt->whereClause,
595 EXPR_KIND_WHERE, "WHERE");
596

Callers 1

transformStmtFunction · 0.85

Calls 13

transformWithClauseFunction · 0.85
setTargetTableFunction · 0.85
transformFromClauseFunction · 0.85
transformWhereClauseFunction · 0.85
transformReturningListFunction · 0.85
makeFromExprFunction · 0.85
parseCheckTableFunctionsFunction · 0.85
assign_query_collationsFunction · 0.85
parseCheckAggregatesFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
errdetailFunction · 0.50

Tested by

no test coverage detected