Skip to content

Commit

Permalink
Fixed bug CORE-2943 : parsing error recursive query with two recursiv…
Browse files Browse the repository at this point in the history
…e parts
  • Loading branch information
hvlad committed Mar 25, 2010
1 parent 2e4fea1 commit 6d9f5e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/dsql/dsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ class CompiledStatement : public dsql_req
// CTE name or via alias. We need to substitute this aliases when processing CTE
// member to resolve field names. Therefore we store all aliases in order of
// occurrence and later use it in backward order (since our parser is right-to-left).
// Also we put CTE name after all such aliases to distinguish aliases for
// different CTE's.
// We also need to repeat this process if main select expression contains union with
// recursive CTE
void addCTEAlias(const dsql_str* alias)
Expand All @@ -530,9 +532,21 @@ class CompiledStatement : public dsql_req
{
return *(--req_curr_cte_alias);
}
void resetCTEAlias()
void resetCTEAlias(const dsql_str* alias)
{
req_curr_cte_alias = req_cte_aliases.end();
const dsql_str* const* begin = req_cte_aliases.begin();

req_curr_cte_alias = req_cte_aliases.end() - 1;
fb_assert(req_curr_cte_alias >= begin);

const dsql_str* curr = *(req_curr_cte_alias);
while (strcmp(curr->str_data, alias->str_data))
{
req_curr_cte_alias--;
fb_assert(req_curr_cte_alias >= begin);

curr = *(req_curr_cte_alias);
}
}

bool isPsql() const
Expand Down
10 changes: 8 additions & 2 deletions src/dsql/pass1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5075,7 +5075,7 @@ static dsql_nod* pass1_derived_table(CompiledStatement* statement, dsql_nod* inp
statement->req_recursive_ctx = context;
statement->req_context = &temp;

statement->resetCTEAlias();
statement->resetCTEAlias(alias);

rse = PASS1_rse(statement, input->nod_arg[e_derived_table_rse], NULL);

Expand Down Expand Up @@ -10717,11 +10717,17 @@ void CompiledStatement::addCTEs(dsql_nod* with)
{
fb_assert((*cte)->nod_type == nod_derived_table);

if (with->nod_flags & NOD_UNION_RECURSIVE) {
if (with->nod_flags & NOD_UNION_RECURSIVE)
{
req_curr_ctes.push(*cte);
PsqlChanger changer(this, false);
req_ctes.add(pass1_recursive_cte(this, *cte));
req_curr_ctes.pop();

// Add CTE name into CTE aliases stack. It allows later to search for
// aliases of given CTE.
const dsql_str* cte_name = (dsql_str*) (*cte)->nod_arg[e_derived_table_alias];
addCTEAlias(cte_name);
}
else {
req_ctes.add(*cte);
Expand Down

0 comments on commit 6d9f5e2

Please sign in to comment.