Skip to content

Commit 584af57

Browse files
committed
Fix #8618: extra quotes in plans for UNLIST function; some minor refactoring and misc style changes
1 parent 081aef0 commit 584af57

File tree

5 files changed

+46
-27
lines changed

5 files changed

+46
-27
lines changed

src/jrd/RecordSourceNodes.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4032,32 +4032,32 @@ TableValueFunctionSourceNode* TableValueFunctionSourceNode::parse(thread_db* tdb
40324032
MemoryPool& pool = *tdbb->getDefaultPool();
40334033

40344034
const auto funcId = csb->csb_blr_reader.getByte();
4035-
auto node = TableValueFunctionSourceNode::parseTableValueFunctions(tdbb, csb, funcId);
4035+
const auto node = TableValueFunctionSourceNode::parseFunction(tdbb, csb, funcId);
40364036

40374037
node->stream = PAR_context(csb, nullptr);
40384038

40394039
CompilerScratch::csb_repeat& element = csb->csb_rpt[node->stream];
4040-
auto tableValueFunctionCsb = node->m_csbTableValueFun = FB_NEW_POOL(pool) jrd_table_value_fun(pool);
4040+
const auto tableValueFunctionCsb = node->m_csbTableValueFun = FB_NEW_POOL(pool) jrd_table_value_fun(pool);
40414041

40424042
tableValueFunctionCsb->funcId = funcId;
4043+
tableValueFunctionCsb->name = node->getName();
40434044

4044-
string aliasString;
4045-
csb->csb_blr_reader.getString(aliasString);
4046-
if (aliasString.hasData())
4047-
node->alias = aliasString;
4045+
AutoPtr<string> aliasString(FB_NEW_POOL(csb->csb_pool) string(csb->csb_pool));
4046+
csb->csb_blr_reader.getString(*aliasString);
4047+
4048+
if (aliasString->hasData())
4049+
node->alias = *aliasString;
40484050
else
40494051
fb_assert(false);
40504052

4051-
tableValueFunctionCsb->name = aliasString;
4052-
40534053
auto count = csb->csb_blr_reader.getWord();
40544054
node->inputList = FB_NEW_POOL(pool) ValueListNode(pool, 0U);
40554055
while (count--)
40564056
node->inputList->add(PAR_parse_value(tdbb, csb));
40574057

40584058
count = csb->csb_blr_reader.getWord();
40594059

4060-
auto recordFormat = Format::newFormat(pool, count);
4060+
const auto recordFormat = Format::newFormat(pool, count);
40614061
ULONG& offset = recordFormat->fmt_length = FLAG_BYTES(recordFormat->fmt_count);
40624062
Format::fmt_desc_iterator descIt = recordFormat->fmt_desc.begin();
40634063
SSHORT fieldId = 0;
@@ -4081,16 +4081,18 @@ TableValueFunctionSourceNode* TableValueFunctionSourceNode::parse(thread_db* tdb
40814081

40824082
element.csb_format = tableValueFunctionCsb->recordFormat = recordFormat;
40834083
element.csb_table_value_fun = tableValueFunctionCsb;
4084+
element.csb_alias = aliasString.release();
40844085

40854086
return node;
40864087
}
40874088

4088-
TableValueFunctionSourceNode* TableValueFunctionSourceNode::parseTableValueFunctions(thread_db* tdbb,
4089-
CompilerScratch* csb,
4090-
const SSHORT blrOp)
4089+
TableValueFunctionSourceNode* TableValueFunctionSourceNode::parseFunction(thread_db* tdbb,
4090+
CompilerScratch* csb,
4091+
const SSHORT blrOp)
40914092
{
40924093
MemoryPool& pool = *tdbb->getDefaultPool();
40934094
TableValueFunctionSourceNode* node = nullptr;
4095+
40944096
switch (blrOp)
40954097
{
40964098
case blr_table_value_fun_unlist:
@@ -4145,7 +4147,7 @@ void TableValueFunctionSourceNode::genBlr(DsqlCompilerScratch* dsqlScratch)
41454147
{
41464148
dsqlScratch->appendUChar(blr_table_value_fun);
41474149

4148-
auto tableValueFunctionContext = dsqlContext->ctx_table_value_fun;
4150+
const auto tableValueFunctionContext = dsqlContext->ctx_table_value_fun;
41494151

41504152
if (tableValueFunctionContext->funName == UnlistFunctionSourceNode::FUNC_NAME)
41514153
dsqlScratch->appendUChar(blr_table_value_fun_unlist);
@@ -4182,17 +4184,17 @@ TableValueFunctionSourceNode* TableValueFunctionSourceNode::copy(thread_db* tdbb
41824184

41834185
MemoryPool& pool = *tdbb->getDefaultPool();
41844186

4185-
auto newStream = copier.csb->nextStream();
4187+
const auto newStream = copier.csb->nextStream();
41864188
copier.remap[stream] = newStream;
41874189

4188-
auto element = CMP_csb_element(copier.csb, newStream);
4190+
const auto element = CMP_csb_element(copier.csb, newStream);
41894191
element->csb_view_stream = copier.remap[0];
41904192
element->csb_format = m_csbTableValueFun->recordFormat;
41914193
element->csb_table_value_fun = m_csbTableValueFun;
41924194
if (alias.hasData())
41934195
element->csb_alias = FB_NEW_POOL(pool) string(pool, alias.c_str());
41944196

4195-
auto newSource = TableValueFunctionSourceNode::parseTableValueFunctions(
4197+
const auto newSource = TableValueFunctionSourceNode::parseFunction(
41964198
tdbb, copier.csb, m_csbTableValueFun->funcId);
41974199

41984200
newSource->inputList = copier.copy(tdbb, inputList);
@@ -4213,7 +4215,7 @@ void TableValueFunctionSourceNode::pass1Source(thread_db* tdbb, CompilerScratch*
42134215
jrd_rel* const parentView = csb->csb_view;
42144216
const StreamType viewStream = csb->csb_view_stream;
42154217

4216-
auto element = CMP_csb_element(csb, stream);
4218+
const auto element = CMP_csb_element(csb, stream);
42174219
element->csb_view = parentView;
42184220
element->csb_view_stream = viewStream;
42194221

@@ -4291,7 +4293,7 @@ void TableValueFunctionSourceNode::setDefaultNameField(DsqlCompilerScratch* /*ds
42914293
{
42924294
if (const auto tableValueFunctionContext = dsqlContext->ctx_table_value_fun)
42934295
{
4294-
MetaName nameFunc = tableValueFunctionContext->funName;
4296+
const auto nameFunc = tableValueFunctionContext->funName;
42954297

42964298
auto i = 0U;
42974299

@@ -4313,9 +4315,9 @@ RecordSource* UnlistFunctionSourceNode::compile(thread_db* tdbb, Optimizer* opt,
43134315
{
43144316
MemoryPool& pool = *tdbb->getDefaultPool();
43154317
const auto csb = opt->getCompilerScratch();
4316-
auto aliasOpt = opt->makeAlias(stream);
4318+
const auto alias = opt->makeAlias(stream);
43174319

4318-
return FB_NEW_POOL(pool) UnlistFunctionScan(csb, stream, aliasOpt, inputList);
4320+
return FB_NEW_POOL(pool) UnlistFunctionScan(csb, stream, alias, inputList);
43194321
}
43204322

43214323
dsql_fld* UnlistFunctionSourceNode::makeField(DsqlCompilerScratch* dsqlScratch)

src/jrd/RecordSourceNodes.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -982,9 +982,9 @@ class TableValueFunctionSourceNode
982982
}
983983
static TableValueFunctionSourceNode* parse(thread_db* tdbb, CompilerScratch* csb,
984984
const SSHORT blrOp);
985-
static TableValueFunctionSourceNode* parseTableValueFunctions(thread_db* tdbb,
986-
CompilerScratch* csb,
987-
const SSHORT blrOp);
985+
static TableValueFunctionSourceNode* parseFunction(thread_db* tdbb,
986+
CompilerScratch* csb,
987+
const SSHORT blrOp);
988988

989989
Firebird::string internalPrint(NodePrinter& printer) const override;
990990
RecordSourceNode* dsqlPass(DsqlCompilerScratch* dsqlScratch) override;
@@ -1011,6 +1011,11 @@ class TableValueFunctionSourceNode
10111011
virtual dsql_fld* makeField(DsqlCompilerScratch* dsqlScratch);
10121012
void setDefaultNameField(DsqlCompilerScratch* dsqlScratch);
10131013

1014+
virtual const char* getName() const
1015+
{
1016+
return nullptr;
1017+
}
1018+
10141019
public:
10151020
MetaName dsqlName;
10161021
MetaName alias;
@@ -1034,6 +1039,11 @@ class UnlistFunctionSourceNode : public TableValueFunctionSourceNode
10341039

10351040
static constexpr char const* FUNC_NAME = "UNLIST";
10361041
static constexpr USHORT DEFAULT_UNLIST_TEXT_LENGTH = 32;
1042+
1043+
const char* getName() const override
1044+
{
1045+
return FUNC_NAME;
1046+
}
10371047
};
10381048

10391049
} // namespace Jrd

src/jrd/exe.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,20 +437,20 @@ typedef Firebird::RightPooledMap<Item, ItemInfo> MapItemInfo;
437437
class jrd_table_value_fun
438438
{
439439
public:
440-
explicit jrd_table_value_fun(MemoryPool& p) : recordFormat(nullptr), fields(p), name(p), funcId(0)
440+
explicit jrd_table_value_fun(MemoryPool& p) : recordFormat(nullptr), fields(p), funcId(0)
441441
{
442442
}
443443

444444
SSHORT getId(const MetaName& fieldName) const
445445
{
446-
SSHORT* id = fields.get(fieldName);
446+
const SSHORT* const id = fields.get(fieldName);
447447
fb_assert(id);
448448
return *id;
449449
}
450450

451451
const Format* recordFormat;
452452
Firebird::LeftPooledMap<MetaName, SSHORT> fields;
453-
Firebird::string name;
453+
MetaName name;
454454
USHORT funcId;
455455
};
456456

src/jrd/recsrc/RecordSource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,7 @@ namespace Jrd
15201520

15211521
virtual bool nextBuffer(thread_db* tdbb) const = 0;
15221522

1523+
MetaName m_name;
15231524
const Firebird::string m_alias;
15241525
};
15251526

src/jrd/recsrc/TableValueFunctionScan.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ TableValueFunctionScan::TableValueFunctionScan(CompilerScratch* csb, StreamType
3838
const string& alias)
3939
: RecordStream(csb, stream), m_alias(csb->csb_pool, alias)
4040
{
41+
const auto tabFunc = csb->csb_rpt[stream].csb_table_value_fun;
42+
fb_assert(tabFunc);
43+
m_name = tabFunc->name;
44+
4145
m_cardinality = DEFAULT_CARDINALITY;
4246
}
4347

@@ -254,7 +258,9 @@ void UnlistFunctionScan::internalGetPlan(thread_db* tdbb, PlanEntry& planEntry,
254258
{
255259
planEntry.className = "FunctionScan";
256260

257-
planEntry.lines.add().text = "Functions " + printName(tdbb, "Unlist", m_alias) + " Scan";
261+
planEntry.lines.add().text = "Function " +
262+
printName(tdbb, m_name.toQuotedString(), m_alias) + " Scan";
263+
258264
printOptInfo(planEntry.lines);
259265

260266
if (m_alias.hasData())

0 commit comments

Comments
 (0)