Skip to content

Commit 3b2f9f5

Browse files
fix(plugin): MCOL-4942 No-table-SELECT now can return empty set (#3413)
The query like "SELECT 1 WHERE 1=0" was returning a row despite unsatisfiable condition in WHERE. Now it returns an empty set.
1 parent e37d621 commit 3b2f9f5

6 files changed

+117
-29
lines changed

dbcon/joblist/jlf_tuplejoblist.cpp

+27-27
Original file line numberDiff line numberDiff line change
@@ -4520,33 +4520,6 @@ void associateTupleJobSteps(JobStepVector& querySteps, JobStepVector& projectSte
45204520
cout << endl;
45214521
}
45224522

4523-
// @bug 2771, handle no table select query
4524-
if (jobInfo.tableList.empty())
4525-
{
4526-
makeNoTableJobStep(querySteps, projectSteps, deliverySteps, jobInfo);
4527-
return;
4528-
}
4529-
4530-
// Create a step vector for each table in the from clause.
4531-
TableInfoMap tableInfoMap;
4532-
4533-
for (uint64_t i = 0; i < jobInfo.tableList.size(); i++)
4534-
{
4535-
uint32_t tableUid = jobInfo.tableList[i];
4536-
tableInfoMap[tableUid] = TableInfo();
4537-
tableInfoMap[tableUid].fTableOid = jobInfo.keyInfo->tupleKeyVec[tableUid].fId;
4538-
tableInfoMap[tableUid].fName = jobInfo.keyInfo->keyName[tableUid];
4539-
tableInfoMap[tableUid].fAlias = jobInfo.keyInfo->tupleKeyVec[tableUid].fTable;
4540-
tableInfoMap[tableUid].fView = jobInfo.keyInfo->tupleKeyVec[tableUid].fView;
4541-
tableInfoMap[tableUid].fSchema = jobInfo.keyInfo->tupleKeyVec[tableUid].fSchema;
4542-
tableInfoMap[tableUid].fSubId = jobInfo.keyInfo->tupleKeyVec[tableUid].fSubId;
4543-
tableInfoMap[tableUid].fColsInColMap = jobInfo.columnMap[tableUid];
4544-
}
4545-
4546-
// Set of the columns being projected.
4547-
for (auto i = jobInfo.pjColList.begin(); i != jobInfo.pjColList.end(); i++)
4548-
jobInfo.returnColSet.insert(i->key);
4549-
45504523
// Strip constantbooleanquerySteps
45514524
for (uint64_t i = 0; i < querySteps.size();)
45524525
{
@@ -4582,6 +4555,33 @@ void associateTupleJobSteps(JobStepVector& querySteps, JobStepVector& projectSte
45824555
}
45834556
}
45844557

4558+
// @bug 2771, handle no table select query
4559+
if (jobInfo.tableList.empty())
4560+
{
4561+
makeNoTableJobStep(querySteps, projectSteps, deliverySteps, jobInfo);
4562+
return;
4563+
}
4564+
4565+
// Create a step vector for each table in the from clause.
4566+
TableInfoMap tableInfoMap;
4567+
4568+
for (uint64_t i = 0; i < jobInfo.tableList.size(); i++)
4569+
{
4570+
uint32_t tableUid = jobInfo.tableList[i];
4571+
tableInfoMap[tableUid] = TableInfo();
4572+
tableInfoMap[tableUid].fTableOid = jobInfo.keyInfo->tupleKeyVec[tableUid].fId;
4573+
tableInfoMap[tableUid].fName = jobInfo.keyInfo->keyName[tableUid];
4574+
tableInfoMap[tableUid].fAlias = jobInfo.keyInfo->tupleKeyVec[tableUid].fTable;
4575+
tableInfoMap[tableUid].fView = jobInfo.keyInfo->tupleKeyVec[tableUid].fView;
4576+
tableInfoMap[tableUid].fSchema = jobInfo.keyInfo->tupleKeyVec[tableUid].fSchema;
4577+
tableInfoMap[tableUid].fSubId = jobInfo.keyInfo->tupleKeyVec[tableUid].fSubId;
4578+
tableInfoMap[tableUid].fColsInColMap = jobInfo.columnMap[tableUid];
4579+
}
4580+
4581+
// Set of the columns being projected.
4582+
for (auto i = jobInfo.pjColList.begin(); i != jobInfo.pjColList.end(); i++)
4583+
jobInfo.returnColSet.insert(i->key);
4584+
45854585
// double check if the function join canditates are still there.
45864586
JobStepVector steps = querySteps;
45874587

dbcon/joblist/tupleconstantstep.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ void TupleConstantStep::constructContanstRow(const JobInfo& jobInfo)
284284
void TupleConstantStep::run()
285285
{
286286
if (fInputJobStepAssociation.outSize() == 0)
287+
{
287288
throw logic_error("No input data list for constant step.");
289+
}
288290

289291
fInputDL = fInputJobStepAssociation.outAt(0)->rowGroupDL();
290292

@@ -585,7 +587,9 @@ void TupleConstantStep::formatMiniStats()
585587
}
586588

587589
// class TupleConstantOnlyStep
588-
TupleConstantOnlyStep::TupleConstantOnlyStep(const JobInfo& jobInfo) : TupleConstantStep(jobInfo)
590+
TupleConstantOnlyStep::TupleConstantOnlyStep(const JobInfo& jobInfo)
591+
: TupleConstantStep(jobInfo)
592+
, fEmptySet(jobInfo.constantFalse)
589593
{
590594
// fExtendedInfo = "TCOS: ";
591595
}
@@ -667,7 +671,10 @@ void TupleConstantOnlyStep::run()
667671

668672
fillInConstants();
669673

670-
fOutputDL->insert(rgDataOut);
674+
if (!fEmptySet)
675+
{
676+
fOutputDL->insert(rgDataOut);
677+
}
671678
}
672679
catch (...)
673680
{

dbcon/joblist/tupleconstantstep.h

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class TupleConstantOnlyStep : public TupleConstantStep
132132
uint32_t nextBand(messageqcpp::ByteStream& bs) override;
133133

134134
protected:
135+
bool fEmptySet;
135136
using TupleConstantStep::fillInConstants;
136137
void fillInConstants() override;
137138
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
DROP DATABASE IF EXISTS MCOL4942;
2+
CREATE DATABASE MCOL4942;
3+
USE MCOL4942;
4+
CREATE TABLE t1col (id INT) ENGINE=Columnstore;
5+
SELECT * FROM
6+
(
7+
SELECT ID
8+
FROM
9+
(
10+
SELECT 1 ID
11+
FROM
12+
t1col
13+
) V
14+
UNION ALL
15+
SELECT ID
16+
FROM
17+
(
18+
SELECT NULL ID WHERE 1111=2222
19+
) V
20+
) U;
21+
ID
22+
DROP DATABASE MCOL4942;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--disable_warnings
2+
DROP DATABASE IF EXISTS MCOL4942;
3+
--enable_warnings
4+
CREATE DATABASE MCOL4942;
5+
USE MCOL4942;
6+
CREATE TABLE t1col (id INT) ENGINE=Columnstore;
7+
8+
SELECT * FROM
9+
10+
(
11+
12+
SELECT ID
13+
14+
FROM
15+
16+
(
17+
18+
SELECT 1 ID
19+
20+
FROM
21+
22+
t1col
23+
24+
) V
25+
26+
UNION ALL
27+
28+
SELECT ID
29+
30+
FROM
31+
32+
(
33+
34+
SELECT NULL ID WHERE 1111=2222
35+
36+
) V
37+
38+
) U;
39+
40+
DROP DATABASE MCOL4942;

utils/loggingcpp/exceptclasses.h

+18
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,24 @@ class ProtocolError : public std::logic_error
283283
} \
284284
} while (0)
285285

286+
#define idblog(x) \
287+
do \
288+
{ \
289+
{ \
290+
std::ostringstream os; \
291+
\
292+
os << __FILE__ << "@" << __LINE__ << ": \'" << x << "\'"; \
293+
std::cerr << os.str() << std::endl; \
294+
logging::MessageLog logger((logging::LoggingID())); \
295+
logging::Message message; \
296+
logging::Message::Args args; \
297+
\
298+
args.add(os.str()); \
299+
message.format(args); \
300+
logger.logErrorMessage(message); \
301+
} \
302+
} while (0)
303+
286304
#define idbassert_s(x, s) \
287305
do \
288306
{ \

0 commit comments

Comments
 (0)