* transformDeleteStmt - * transforms a Delete Statement */
| 537 | * transforms a Delete Statement |
| 538 | */ |
| 539 | static Query * |
| 540 | transformDeleteStmt(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 |
no test coverage detected