Skip to content
Snippets Groups Projects
Commit b4c503be authored by Arseniy Volynets's avatar Arseniy Volynets
Browse files

fix: use MotionPolicy::Full for <>, not in

parent b67a8100
No related branches found
No related tags found
1 merge request!1414sbroad import
......@@ -132,6 +132,61 @@ g.test_not_eq = function()
})
end
g.test_not_eq2 = function()
-- "t" contains:
-- [1, 4.2]
-- [2, decimal(6.66)]
-- [3, 0.0]
-- [4, 0.0]
local api = cluster:server("api-1").net_box
local r, err = api:call("sbroad.execute", {
[[insert into "t" ("id", "a") values (?, ?), (?, ?)]],
{3, 0.0, 4, 0.0}
})
t.assert_equals(err, nil)
t.assert_equals(r, {row_count = 2})
-- make sure table is located on both storages, not only on one storage
local storage1 = cluster:server("storage-1-1").net_box
r, err = storage1:call("box.execute", {
[[select * from "t"]], {}
})
t.assert_equals(err, nil)
t.assert_equals(true, next(r.rows) ~= nil)
local storage2 = cluster:server("storage-2-1").net_box
r, err = storage2:call("box.execute", {
[[select * from "t"]], {}
})
t.assert_equals(err, nil)
t.assert_equals(true, next(r.rows) ~= nil)
r, err = api:call(
"sbroad.execute",
{
[[
SELECT "id", u FROM "t" join
(select "id" as u from "t") as q
on "t"."id" <> q.u
]],
{}
}
)
t.assert_equals(err, nil)
t.assert_items_equals(r, {
metadata = {
{name = "t.id", type = "integer"},
{name = "Q.U", type = "integer"}
},
rows = {
{1, 2}, {1, 3}, {1, 4},
{2, 1}, {2, 3}, {2, 4},
{3, 1}, {3, 2}, {3, 4},
{4, 1}, {4, 2}, {4, 3},
},
})
end
g.test_simple_shard_key_union_query = function()
local api = cluster:server("api-1").net_box
......
......@@ -126,14 +126,15 @@ fn front_params6() {
selection ROW("test_space"."sys_op") = ROW(0) or ROW("test_space"."id") not in ROW($0)
scan "test_space"
subquery $0:
scan
union all
projection ("test_space"."id" -> "id")
selection ROW("test_space"."sys_op") = ROW(1)
scan "test_space"
projection ("test_space"."id" -> "id")
selection ROW("test_space"."sys_op") = ROW(2)
scan "test_space"
motion [policy: full]
scan
union all
projection ("test_space"."id" -> "id")
selection ROW("test_space"."sys_op") = ROW(1)
scan "test_space"
projection ("test_space"."id" -> "id")
selection ROW("test_space"."sys_op") = ROW(2)
scan "test_space"
"#,
);
......
......@@ -290,7 +290,7 @@ impl Plan {
) -> Result<MotionPolicy, SbroadError> {
let outer_dist = self.get_distribution(outer_id)?;
let inner_dist = self.get_distribution(inner_id)?;
if Bool::Eq == *op || Bool::In == *op || Bool::NotEq == *op || Bool::NotIn == *op {
if Bool::Eq == *op || Bool::In == *op {
if let Distribution::Segment {
keys: ref keys_outer,
} = outer_dist
......@@ -846,10 +846,15 @@ impl Plan {
}
(Expression::Row { .. }, Expression::Row { .. }) => {
match bool_op.op {
Bool::Eq | Bool::In | Bool::NotEq | Bool::NotIn => {
Bool::Eq | Bool::In => {
self.join_policy_for_eq(rel_id, bool_op.left, bool_op.right)?
}
Bool::Gt | Bool::GtEq | Bool::Lt | Bool::LtEq => MotionPolicy::Full,
Bool::Gt
| Bool::GtEq
| Bool::Lt
| Bool::LtEq
| Bool::NotEq
| Bool::NotIn => MotionPolicy::Full,
Bool::And | Bool::Or => {
// "a and 1" or "a or 1" expressions make no sense.
return Err(SbroadError::Unsupported(
......
......@@ -2,7 +2,7 @@ use crate::ir::operator::Relational;
use crate::ir::transformation::helpers::sql_to_ir;
use crate::ir::transformation::redistribution::tests::get_motion_id;
use crate::ir::transformation::redistribution::{Key, MotionPolicy};
use crate::ir::Slices;
use crate::ir::{Slice, Slices};
use pretty_assertions::assert_eq;
#[test]
......@@ -28,7 +28,7 @@ fn not_in2() {
let mut plan = sql_to_ir(query, vec![]);
plan.add_motions().unwrap();
assert_eq!(Slices::empty(), plan.slices);
assert_eq!(Slices::from(vec![Slice { slice: vec![64] }]), plan.slices);
}
#[test]
......@@ -41,15 +41,7 @@ fn not_in3() {
let motion_id = *get_motion_id(&plan, 0, 0).unwrap();
let motion = plan.get_relation_node(motion_id).unwrap();
if let Relational::Motion { policy, .. } = motion {
assert_eq!(
*policy,
MotionPolicy::Segment(
(Key {
positions: vec![0, 1]
})
.into()
)
);
assert_eq!(*policy, MotionPolicy::Full);
} else {
panic!("Expected a motion node");
}
......@@ -65,15 +57,7 @@ fn not_in4() {
let motion_id = *get_motion_id(&plan, 0, 0).unwrap();
let motion = plan.get_relation_node(motion_id).unwrap();
if let Relational::Motion { policy, .. } = motion {
assert_eq!(
*policy,
MotionPolicy::Segment(
(Key {
positions: vec![1, 0]
})
.into()
)
);
assert_eq!(*policy, MotionPolicy::Full);
} else {
panic!("Expected a motion node");
}
......@@ -89,15 +73,7 @@ fn not_in5() {
let motion_id = *get_motion_id(&plan, 0, 0).unwrap();
let motion = plan.get_relation_node(motion_id).unwrap();
if let Relational::Motion { policy, .. } = motion {
assert_eq!(
*policy,
MotionPolicy::Segment(
(Key {
positions: vec![0, 1]
})
.into()
)
);
assert_eq!(*policy, MotionPolicy::Full);
} else {
panic!("Expected a motion node");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment