Skip to content

Commit

Permalink
Fixed CORE-2584 - Wrong results for CASE used together with GROUP BY
Browse files Browse the repository at this point in the history
  • Loading branch information
asfernandes committed Aug 6, 2009
1 parent ae4bc99 commit 88495f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/dsql/gen.cpp
Expand Up @@ -2729,8 +2729,12 @@ static void gen_simple_case( CompiledStatement* statement, const dsql_nod* node)
{
stuff(statement, blr_value_if);
stuff(statement, blr_eql);
GEN_expr(statement, node->nod_arg[(wptr == when_list->nod_arg ?
e_simple_case_case_operand : e_simple_case_case_operand2)]);

if (wptr == when_list->nod_arg || !node->nod_arg[e_simple_case_case_operand2])
GEN_expr(statement, node->nod_arg[e_simple_case_case_operand]);
else
GEN_expr(statement, node->nod_arg[e_simple_case_case_operand2]);

GEN_expr(statement, *wptr);
GEN_expr(statement, *rptr);
}
Expand Down
11 changes: 6 additions & 5 deletions src/dsql/pass1.cpp
Expand Up @@ -8318,15 +8318,16 @@ static dsql_nod* pass1_simple_case( CompiledStatement* statement, dsql_nod* inpu
DEV_BLKCHK(input->nod_arg[0], dsql_type_nod);

dsql_nod* node = MAKE_node(nod_simple_case, 4);
node->nod_count = 3; // we do not want to reprocess last parameter later
node->nod_count = 3; // we do not want to reprocess e_simple_case_case_operand2 later

// build case_operand node
node->nod_arg[e_simple_case_case_operand] = PASS1_node(statement, input->nod_arg[0]);
node->nod_arg[e_simple_case_case_operand2] =
pass1_hidden_variable(statement, node->nod_arg[e_simple_case_case_operand]);
node->nod_arg[e_simple_case_case_operand2] = pass1_hidden_variable(
statement, node->nod_arg[e_simple_case_case_operand]);

if (!node->nod_arg[e_simple_case_case_operand2])
node->nod_arg[e_simple_case_case_operand2] = node->nod_arg[e_simple_case_case_operand];
// If a hidden variable was generated, it will be stored in e_simple_case_case_operand2 and
// we'll use it in GEN. Otherwise, e_simple_case_case_operand2 is NULL and we should use the
// original expression (e_simple_case_case_operand) in GEN.

dsql_nod* list = input->nod_arg[1];

Expand Down

0 comments on commit 88495f2

Please sign in to comment.