[
https://issues.apache.org/jira/browse/IGNITE-22953?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Maksim Zhuravkov updated IGNITE-22953:
--------------------------------------
Description:
{noformat}
@Test
public void test() {
sql("CREATE TABLE t(a INT PRIMARY KEY, b INT)");
sql("INSERT INTO t (a, b) SELECT 1, 1 UNION SELECT 1, 1");
}
{noformat}
Expected result: Constrain violation, no rows inserted.
Actual result: a table with a single record.
*Logical plan*
{noformat}
LogicalTableModify(table=[[PUBLIC, T]], operation=[INSERT], flattened=[false])
LogicalUnion(all=[false])
LogicalValues(tuples=[[{ 1, 1 }]])
LogicalValues(tuples=[[{ 1, 1 }]])
{noformat}
*Final query plan*
The ColocatedHashAggregate is on top of a UnionAll node removes duplicate
records produced its input. This aggregate should not be present in a plan.
{noformat}
Project(ROWCOUNT=[CAST($0):BIGINT NOT NULL]): rowcount = 2.0, cumulative cost =
IgniteCost [rowCount=16.0, cpu=22.0, memory=28.0, io=2.0, network=10.0], id =
130
ColocatedHashAggregate(group=[{}], agg#0=[$SUM0($0)]): rowcount = 2.0,
cumulative cost = IgniteCost [rowCount=13.0, cpu=19.0, memory=27.0, io=1.0,
network=9.0], id = 129
Exchange(distribution=[single]): rowcount = 2.0, cumulative cost =
IgniteCost [rowCount=11.0, cpu=17.0, memory=17.0, io=1.0, network=9.0], id = 128
TableModify(table=[[PUBLIC, T]], operation=[INSERT], flattened=[false],
tableId=[11]): rowcount = 2.0, cumulative cost = IgniteCost [rowCount=9.0,
cpu=15.0, memory=17.0, io=1.0, network=1.0], id = 127
TrimExchange(distribution=[affinity[tableId=11, zoneId=11][0]]):
rowcount = 2.0, cumulative cost = IgniteCost [rowCount=8.0, cpu=14.0,
memory=16.0, io=0.0, network=0.0], id = 126
ColocatedHashAggregate(group=[{0, 1}]): rowcount = 2.0, cumulative
cost = IgniteCost [rowCount=6.0, cpu=6.0, memory=16.0, io=0.0, network=0.0], id
= 125
UnionAll(all=[true]): rowcount = 2.0, cumulative cost = IgniteCost
[rowCount=4.0, cpu=4.0, memory=0.0, io=0.0, network=0.0], id = 124
Values(tuples=[[{ 1, 1 }]]): rowcount = 1.0, cumulative cost =
IgniteCost [rowCount=1.0, cpu=1.0, memory=0.0, io=0.0, network=0.0], id = 122
Values(tuples=[[{ 1, 1 }]]): rowcount = 1.0, cumulative cost =
IgniteCost [rowCount=1.0, cpu=1.0, memory=0.0, io=0.0, network=0.0], id = 123
{noformat}
was:
{noformat}
@Test
public void test() {
sql("CREATE TABLE t(a INT PRIMARY KEY, b INT)");
sql("INSERT INTO t (a, b) SELECT 1, 1 UNION SELECT 1, 1");
}
{noformat}
Expected result: Constrain violation, no rows inserted.
Actual result: a table with a single record.
Query plan:
ColocatedHashAggregate on top of UnionAll removes duplicate records produced
its input. This aggregate should not be present in a plan.
{noformat}
Project(ROWCOUNT=[CAST($0):BIGINT NOT NULL]): rowcount = 2.0, cumulative cost =
IgniteCost [rowCount=16.0, cpu=22.0, memory=28.0, io=2.0, network=10.0], id =
130
ColocatedHashAggregate(group=[{}], agg#0=[$SUM0($0)]): rowcount = 2.0,
cumulative cost = IgniteCost [rowCount=13.0, cpu=19.0, memory=27.0, io=1.0,
network=9.0], id = 129
Exchange(distribution=[single]): rowcount = 2.0, cumulative cost =
IgniteCost [rowCount=11.0, cpu=17.0, memory=17.0, io=1.0, network=9.0], id = 128
TableModify(table=[[PUBLIC, T]], operation=[INSERT], flattened=[false],
tableId=[11]): rowcount = 2.0, cumulative cost = IgniteCost [rowCount=9.0,
cpu=15.0, memory=17.0, io=1.0, network=1.0], id = 127
TrimExchange(distribution=[affinity[tableId=11, zoneId=11][0]]):
rowcount = 2.0, cumulative cost = IgniteCost [rowCount=8.0, cpu=14.0,
memory=16.0, io=0.0, network=0.0], id = 126
ColocatedHashAggregate(group=[{0, 1}]): rowcount = 2.0, cumulative
cost = IgniteCost [rowCount=6.0, cpu=6.0, memory=16.0, io=0.0, network=0.0], id
= 125
UnionAll(all=[true]): rowcount = 2.0, cumulative cost = IgniteCost
[rowCount=4.0, cpu=4.0, memory=0.0, io=0.0, network=0.0], id = 124
Values(tuples=[[{ 1, 1 }]]): rowcount = 1.0, cumulative cost =
IgniteCost [rowCount=1.0, cpu=1.0, memory=0.0, io=0.0, network=0.0], id = 122
Values(tuples=[[{ 1, 1 }]]): rowcount = 1.0, cumulative cost =
IgniteCost [rowCount=1.0, cpu=1.0, memory=0.0, io=0.0, network=0.0], id = 123
{noformat}
> Sql. Incorrect query plan for INSERT INTO t SELECT .. UNION SELECT ..
> ---------------------------------------------------------------------
>
> Key: IGNITE-22953
> URL: https://issues.apache.org/jira/browse/IGNITE-22953
> Project: Ignite
> Issue Type: Improvement
> Components: sql
> Reporter: Maksim Zhuravkov
> Priority: Major
> Labels: ignite-3
>
> {noformat}
> @Test
> public void test() {
> sql("CREATE TABLE t(a INT PRIMARY KEY, b INT)");
> sql("INSERT INTO t (a, b) SELECT 1, 1 UNION SELECT 1, 1");
> }
> {noformat}
> Expected result: Constrain violation, no rows inserted.
> Actual result: a table with a single record.
> *Logical plan*
> {noformat}
> LogicalTableModify(table=[[PUBLIC, T]], operation=[INSERT], flattened=[false])
> LogicalUnion(all=[false])
> LogicalValues(tuples=[[{ 1, 1 }]])
> LogicalValues(tuples=[[{ 1, 1 }]])
> {noformat}
> *Final query plan*
> The ColocatedHashAggregate is on top of a UnionAll node removes duplicate
> records produced its input. This aggregate should not be present in a plan.
> {noformat}
> Project(ROWCOUNT=[CAST($0):BIGINT NOT NULL]): rowcount = 2.0, cumulative cost
> = IgniteCost [rowCount=16.0, cpu=22.0, memory=28.0, io=2.0, network=10.0], id
> = 130
> ColocatedHashAggregate(group=[{}], agg#0=[$SUM0($0)]): rowcount = 2.0,
> cumulative cost = IgniteCost [rowCount=13.0, cpu=19.0, memory=27.0, io=1.0,
> network=9.0], id = 129
> Exchange(distribution=[single]): rowcount = 2.0, cumulative cost =
> IgniteCost [rowCount=11.0, cpu=17.0, memory=17.0, io=1.0, network=9.0], id =
> 128
> TableModify(table=[[PUBLIC, T]], operation=[INSERT], flattened=[false],
> tableId=[11]): rowcount = 2.0, cumulative cost = IgniteCost [rowCount=9.0,
> cpu=15.0, memory=17.0, io=1.0, network=1.0], id = 127
> TrimExchange(distribution=[affinity[tableId=11, zoneId=11][0]]):
> rowcount = 2.0, cumulative cost = IgniteCost [rowCount=8.0, cpu=14.0,
> memory=16.0, io=0.0, network=0.0], id = 126
> ColocatedHashAggregate(group=[{0, 1}]): rowcount = 2.0, cumulative
> cost = IgniteCost [rowCount=6.0, cpu=6.0, memory=16.0, io=0.0, network=0.0],
> id = 125
> UnionAll(all=[true]): rowcount = 2.0, cumulative cost =
> IgniteCost [rowCount=4.0, cpu=4.0, memory=0.0, io=0.0, network=0.0], id = 124
> Values(tuples=[[{ 1, 1 }]]): rowcount = 1.0, cumulative cost =
> IgniteCost [rowCount=1.0, cpu=1.0, memory=0.0, io=0.0, network=0.0], id = 122
> Values(tuples=[[{ 1, 1 }]]): rowcount = 1.0, cumulative cost =
> IgniteCost [rowCount=1.0, cpu=1.0, memory=0.0, io=0.0, network=0.0], id = 123
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)