1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-11 10:01:57 +03:00

SEARCH and CYCLE clauses

This adds the SQL standard feature that adds the SEARCH and CYCLE
clauses to recursive queries to be able to do produce breadth- or
depth-first search orders and detect cycles.  These clauses can be
rewritten into queries using existing syntax, and that is what this
patch does in the rewriter.

Reviewed-by: Vik Fearing <vik@postgresfriends.org>
Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/db80ceee-6f97-9b4a-8ee8-3ba0c58e5be2@2ndquadrant.com
This commit is contained in:
Peter Eisentraut
2021-02-01 13:54:59 +01:00
parent bb513b364b
commit 3696a600e2
28 changed files with 2301 additions and 33 deletions

View File

@ -3077,6 +3077,34 @@ _outWithClause(StringInfo str, const WithClause *node)
WRITE_LOCATION_FIELD(location);
}
static void
_outCTESearchClause(StringInfo str, const CTESearchClause *node)
{
WRITE_NODE_TYPE("CTESEARCHCLAUSE");
WRITE_NODE_FIELD(search_col_list);
WRITE_BOOL_FIELD(search_breadth_first);
WRITE_STRING_FIELD(search_seq_column);
WRITE_LOCATION_FIELD(location);
}
static void
_outCTECycleClause(StringInfo str, const CTECycleClause *node)
{
WRITE_NODE_TYPE("CTECYCLECLAUSE");
WRITE_NODE_FIELD(cycle_col_list);
WRITE_STRING_FIELD(cycle_mark_column);
WRITE_NODE_FIELD(cycle_mark_value);
WRITE_NODE_FIELD(cycle_mark_default);
WRITE_STRING_FIELD(cycle_path_column);
WRITE_LOCATION_FIELD(location);
WRITE_OID_FIELD(cycle_mark_type);
WRITE_INT_FIELD(cycle_mark_typmod);
WRITE_OID_FIELD(cycle_mark_collation);
WRITE_OID_FIELD(cycle_mark_neop);
}
static void
_outCommonTableExpr(StringInfo str, const CommonTableExpr *node)
{
@ -3086,6 +3114,8 @@ _outCommonTableExpr(StringInfo str, const CommonTableExpr *node)
WRITE_NODE_FIELD(aliascolnames);
WRITE_ENUM_FIELD(ctematerialized, CTEMaterialize);
WRITE_NODE_FIELD(ctequery);
WRITE_NODE_FIELD(search_clause);
WRITE_NODE_FIELD(cycle_clause);
WRITE_LOCATION_FIELD(location);
WRITE_BOOL_FIELD(cterecursive);
WRITE_INT_FIELD(cterefcount);
@ -4262,6 +4292,12 @@ outNode(StringInfo str, const void *obj)
case T_WithClause:
_outWithClause(str, obj);
break;
case T_CTESearchClause:
_outCTESearchClause(str, obj);
break;
case T_CTECycleClause:
_outCTECycleClause(str, obj);
break;
case T_CommonTableExpr:
_outCommonTableExpr(str, obj);
break;