Permalink
Browse files

Remove optimization for an insertion into a join

  • Loading branch information...
1 parent ee10a02 commit 608a2717f1191f0153fb3ede6041ad7dc879a618 @dkubb committed May 30, 2012
@@ -51,62 +51,8 @@ def optimize
end # class OrderLeft
- class JoinLeft < self
-
- # Test if the left operand is a Join
- #
- # @return [Boolean]
- #
- # @api private
- def optimizable?
- left.kind_of?(Veritas::Algebra::Join)
- end
-
- # An Insertion into a Join applies to the left and right operand
- #
- # @return [Veritas::Algebra::Join]
- #
- # @api private
- def optimize
- wrap_left.join(wrap_right)
- end
-
- private
-
- # Wrap the left operand of the join in an insertion
- #
- # @return [Veritas::Relation::Operation::Insertion]
- #
- # @api private
- def wrap_left
- insert(left.left)
- end
-
- # Wrap the right operand of the join in an insertion
- #
- # @return [Veritas::Relation::Operation::Insertion]
- #
- # @api private
- def wrap_right
- insert(left.right)
- end
-
- # Insert a projection of the right operand into the relation
- #
- # @param [Veritas::Relation] relation
- #
- # @return [Veritas::Relation::Operation::Insertion]
- #
- # @api private
- def insert(relation)
- relation.insert(right.project(relation.header))
- end
-
- end # class Join
-
Veritas::Relation::Operation::Insertion.optimizer = chain(
OrderLeft,
- JoinLeft,
MaterializedOperands,
UnoptimizedOperands
)
@@ -13,37 +13,6 @@
let(:left_body) { [ [ 1 ] ].each }
let(:right_body) { [ [ 2 ] ].each }
- context 'left is a join' do
- let(:left) { left_left.join(left_right) }
- let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 2, 'Jane Doe' ] ].each) }
- let(:left_left) { Relation.new([ [ :id, Integer ] ], [ [ 1 ] ].each) }
- let(:left_right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 1, 'John Doe' ], [ 2, 'Jane Doe' ] ].each) }
-
- it 'returns an equivalent relation to the unoptimized operation' do
- should == object
- end
-
- it 'does not execute left_body#each' do
- left_body.should_not_receive(:each)
- subject
- end
-
- it 'does not execute right_body#each' do
- right_body.should_not_receive(:each)
- subject
- end
-
- it { should be_instance_of(Algebra::Join) }
-
- # check to make sure the insertion is pushed-down to the left and right
- # relations, and the right projection is factored out since the projected
- # attributes are the same as the header
- its(:left) { should eql(left_left.insert(right.project([ :id ]))) }
- its(:right) { should eql(left_right.insert(right)) }
-
- it_should_behave_like 'an optimize method'
- end
-
context 'left is a product' do
let(:left) { left_left.product(left_right) }
let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 2, 'Jane Doe' ] ].each) }
@@ -1,29 +0,0 @@
-# encoding: utf-8
-
-require 'spec_helper'
-
-describe Optimizer::Relation::Operation::Insertion::JoinLeft, '#optimizable?' do
- subject { object.optimizable? }
-
- let(:object) { described_class.new(relation) }
- let(:relation) { left.insert(right) }
- let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 2, 'Jane Doe' ] ].each) }
- let(:left_left) { Relation.new([ [ :id, Integer ] ], [ [ 1 ] ].each) }
- let(:left_right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 1, 'John Doe' ], [ 2, 'Jane Doe' ] ].each) }
-
- before do
- object.operation.should be_kind_of(Relation::Operation::Insertion)
- end
-
- context 'when the left is a join' do
- let(:left) { left_left.join(left_right) }
-
- it { should be(true) }
- end
-
- context 'when the left is not a join' do
- let(:left) { left_right }
-
- it { should be(false) }
- end
-end
@@ -1,23 +0,0 @@
-# encoding: utf-8
-
-require 'spec_helper'
-
-describe Optimizer::Relation::Operation::Insertion::JoinLeft, '#optimize' do
- subject { object.optimize }
-
- let(:object) { described_class.new(relation) }
- let(:relation) { left.insert(right) }
- let(:left) { left_left.join(left_right) }
- let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 2, 'Jane Doe' ] ].each) }
- let(:left_left) { Relation.new([ [ :id, Integer ] ], [ [ 1 ] ].each) }
- let(:left_right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 1, 'John Doe' ], [ 2, 'Jane Doe' ] ].each) }
-
- before do
- object.should be_optimizable
- end
-
- it { should be_instance_of(Algebra::Join) }
-
- its(:left) { should eql(left_left.insert(right.project([ :id ]))) }
- its(:right) { should eql(left_right.insert(right.project([ :id, :name ]))) }
-end

0 comments on commit 608a271

Please sign in to comment.