Skip to content

Commit 9760157

Browse files
authored
Fix #8822: Some procedures containing LIST aggregate function are not restored in Firebird 6.0 (#8839)
* Fix #8822: Some procedures containing LIST aggregate function are not restored in Firebird 6.0 * Add comment as requested by Adriano
1 parent e88f729 commit 9760157

5 files changed

Lines changed: 35 additions & 9 deletions

File tree

src/dsql/AggNodes.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,12 @@ DmlNode* ListAggNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScratch*
935935
ListAggNode* node = FB_NEW_POOL(pool) ListAggNode(pool, (blrOp == blr_agg_list_distinct));
936936
node->arg = PAR_parse_value(tdbb, csb);
937937
node->delimiter = PAR_parse_value(tdbb, csb);
938-
if (csb->csb_blr_reader.peekByte() == blr_sort)
939-
node->sort = PAR_sort(tdbb, csb, blr_sort, true);
938+
if (csb->csb_blr_reader.peekByte() == blr_within_group_order)
939+
{
940+
csb->csb_blr_reader.getByte(); // skip blr_within_group_order
941+
if (const auto count = csb->csb_blr_reader.getByte())
942+
node->sort = PAR_sort_internal(tdbb, csb, true, count);
943+
}
940944

941945
return node;
942946
}
@@ -966,7 +970,7 @@ void ListAggNode::genBlr(DsqlCompilerScratch* dsqlScratch)
966970
{
967971
AggNode::genBlr(dsqlScratch);
968972
if (dsqlOrderClause)
969-
GEN_sort(dsqlScratch, blr_sort, dsqlOrderClause);
973+
GEN_sort(dsqlScratch, blr_within_group_order, dsqlOrderClause);
970974
}
971975

972976
bool ListAggNode::setParameterType(DsqlCompilerScratch* dsqlScratch,

src/dsql/parse.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8684,7 +8684,7 @@ listagg_count_indication
86848684

86858685
%type <valueListNode> within_group_specification_opt
86868686
within_group_specification_opt
8687-
: /* nothing */ { $$ = newNode<ValueListNode>(0); }
8687+
: /* nothing */ { $$ = nullptr; }
86888688
| within_group_specification { $$ = $1; }
86898689
;
86908690

src/include/firebird/impl/blr.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,12 @@
507507

508508
// Table value function
509509
#define blr_table_value_fun (unsigned char) 229
510+
// subcodes of blr_table_value_fun
510511
#define blr_table_value_fun_unlist (unsigned char) 1
511512
#define blr_table_value_fun_gen_series (unsigned char) 2
512513

513514
#define blr_for_range (unsigned char) 230
515+
// subcodes of blr_for_range
514516
#define blr_for_range_variable (unsigned char) 1
515517
#define blr_for_range_initial_value (unsigned char) 2
516518
#define blr_for_range_final_value (unsigned char) 3
@@ -523,9 +525,11 @@
523525
#define blr_gen_id3 (unsigned char) 231
524526
#define blr_default2 (unsigned char) 232
525527
#define blr_current_schema (unsigned char) 233
526-
#define blr_flags (unsigned char) 234
527528

529+
#define blr_flags (unsigned char) 234
528530
// subcodes of blr_flags
529531
#define blr_flags_search_system_schema (unsigned char) 1
530532

533+
#define blr_within_group_order (unsigned char) 235
534+
531535
#endif // FIREBIRD_IMPL_BLR_H

src/jrd/blp.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ static inline constexpr struct
196196
{"cursor_stmt", cursor_stmt},
197197
{"current_timestamp2", byte_line},
198198
{"current_time2", byte_line},
199-
{"agg_list", two}, // 170
200-
{"agg_list_distinct", two},
199+
{"agg_list", list_function}, // 170
200+
{"agg_list_distinct", list_function},
201201
{"modify2", modify2},
202202
{"erase2", erase2},
203203
// New BLR in FB1
@@ -229,7 +229,7 @@ static inline constexpr struct
229229
{"partition_by", partition_by},
230230
{"continue_loop", byte_line},
231231
{"procedure4", procedure4},
232-
{"agg_function", function},
232+
{"agg_function", agg_function},
233233
{"substring_similar", three}, // 200
234234
{"bool_as_value", one},
235235
{"coalesce", byte_args},
@@ -267,5 +267,6 @@ static inline constexpr struct
267267
{"default2", default2},
268268
{"current_schema", zero},
269269
{NULL, NULL}, // flags - part of header
270+
{NULL, NULL}, // blr_within_group_order - part of blr_agg_list[_distinct] and blr_agg_function
270271
{0, 0}
271272
};

src/yvalve/gds.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ constexpr int op_invoke_function = 33;
327327
constexpr int op_invsel_procedure = 34;
328328
constexpr int op_table_value_fun = 35;
329329
constexpr int op_for_range = 36;
330+
constexpr int op_within_group_order = 37;
330331

331332
static constexpr UCHAR
332333
// generic print formats
@@ -433,7 +434,9 @@ static constexpr UCHAR
433434
default2[] = { op_line, op_indent, op_byte, op_literal,
434435
op_line, op_indent, op_byte, op_literal,
435436
op_line, op_indent, op_byte, op_literal,
436-
op_pad, op_line, 0};
437+
op_pad, op_line, 0 },
438+
list_function[] = { op_line, op_verb, op_verb, op_within_group_order, 0 },
439+
agg_function[] = { op_byte, op_literal, op_byte, op_line, op_args, op_within_group_order, 0 };
437440

438441

439442
#include "../jrd/blp.h"
@@ -4432,6 +4435,20 @@ static void blr_print_verb(gds_ctl* control, SSHORT level)
44324435
break;
44334436
}
44344437

4438+
case op_within_group_order:
4439+
{
4440+
if (control->ctl_blr_reader.peekByte() == blr_within_group_order)
4441+
{
4442+
blr_indent(control, level);
4443+
blr_print_blr(control, control->ctl_blr_reader.getByte());
4444+
n = blr_print_byte(control);
4445+
blr_print_line(control, (SSHORT) offset);
4446+
while (--n >= 0)
4447+
blr_print_verb(control, level + 1);
4448+
}
4449+
break;
4450+
}
4451+
44354452
default:
44364453
fb_assert(false);
44374454
break;

0 commit comments

Comments
 (0)