@@ -431,8 +431,6 @@ void AndShortCircuit::Transform(std::shared_ptr<AbsExpr_Expression> input,
431431 (void )context;
432432 (void )transformed;
433433
434- LOG_DEBUG (" Transforming AND!" );
435-
436434 // Asserting guarantees provided by the GroupExprBindingIterator
437435 // Structure: (FALSE AND <any expression>)
438436 PELOTON_ASSERT (input->Children ().size () == 2 );
@@ -485,8 +483,6 @@ void OrShortCircuit::Transform(std::shared_ptr<AbsExpr_Expression> input,
485483 (void )context;
486484 (void )transformed;
487485
488- LOG_DEBUG (" Transforming OR!" );
489-
490486 // Asserting guarantees provided by the GroupExprBindingIterator
491487 // Structure: (TRUE OR <any expression>)
492488 PELOTON_ASSERT (input->Children ().size () == 2 );
@@ -509,5 +505,104 @@ void OrShortCircuit::Transform(std::shared_ptr<AbsExpr_Expression> input,
509505}
510506
511507
508+ NullLookupOnNotNullColumn::NullLookupOnNotNullColumn () {
509+ type_ = RuleType::NULL_LOOKUP_ON_NOT_NULL_COLUMN;
510+
511+ // Structure: [T.X IS NULL]
512+ match_pattern = std::make_shared<Pattern<ExpressionType>>(ExpressionType::OPERATOR_IS_NULL);
513+ auto child = std::make_shared<Pattern<ExpressionType>>(ExpressionType::VALUE_TUPLE);
514+
515+ match_pattern->AddChild (child);
516+ }
517+
518+ int NullLookupOnNotNullColumn::Promise (GroupExprTemplate *group_expr, OptimizeContextTemplate *context) const {
519+ (void )group_expr;
520+ (void )context;
521+ return static_cast <int >(RulePriority::HIGH);
522+ }
523+
524+ bool NullLookupOnNotNullColumn::Check (std::shared_ptr<AbsExpr_Expression> plan, OptimizeContextTemplate *context) const {
525+ (void )plan;
526+ (void )context;
527+ return true ;
528+ }
529+
530+ void NullLookupOnNotNullColumn::Transform (std::shared_ptr<AbsExpr_Expression> input,
531+ std::vector<std::shared_ptr<AbsExpr_Expression>> &transformed,
532+ OptimizeContextTemplate *context) const {
533+ (void )context;
534+ (void )transformed;
535+
536+ // Asserting guarantees provided by the GroupExprBindingIterator
537+ // Structure: (TRUE OR <any expression>)
538+ PELOTON_ASSERT (input->Children ().size () == 1 );
539+ PELOTON_ASSERT (input->Op ().GetType () == ExpressionType::OPERATOR_IS_NULL);
540+
541+ std::shared_ptr<AbsExpr_Expression> child = input->Children ()[0 ];
542+ PELOTON_ASSERT (child->Children ().size () == 0 );
543+ PELOTON_ASSERT (child->Op ().GetType () == ExpressionType::VALUE_TUPLE);
544+
545+ std::shared_ptr<expression::TupleValueExpression> tuple_expr = std::dynamic_pointer_cast<expression::TupleValueExpression>(child->Op ().GetExpr ());
546+
547+ // Only transform into [FALSE] if the tuple value expression is specifically non-NULL,
548+ // otherwise do nothing
549+ if (tuple_expr->GetIsNotNull ()) {
550+ type::Value val_false = type::ValueFactory::GetBooleanValue (false );
551+ std::shared_ptr<expression::ConstantValueExpression> false_expr = std::make_shared<expression::ConstantValueExpression>(val_false);
552+ std::shared_ptr<AbsExpr_Expression> false_container = std::make_shared<AbsExpr_Expression>(AbsExpr_Container (false_expr));
553+ transformed.push_back (false_container);
554+ }
555+ }
556+
557+
558+ NotNullLookupOnNotNullColumn::NotNullLookupOnNotNullColumn () {
559+ type_ = RuleType::NOT_NULL_LOOKUP_ON_NOT_NULL_COLUMN;
560+
561+ // Structure: [T.X IS NOT NULL]
562+ match_pattern = std::make_shared<Pattern<ExpressionType>>(ExpressionType::OPERATOR_IS_NOT_NULL);
563+ auto child = std::make_shared<Pattern<ExpressionType>>(ExpressionType::VALUE_TUPLE);
564+
565+ match_pattern->AddChild (child);
566+ }
567+
568+ int NotNullLookupOnNotNullColumn::Promise (GroupExprTemplate *group_expr, OptimizeContextTemplate *context) const {
569+ (void )group_expr;
570+ (void )context;
571+ return static_cast <int >(RulePriority::HIGH);
572+ }
573+
574+ bool NotNullLookupOnNotNullColumn::Check (std::shared_ptr<AbsExpr_Expression> plan, OptimizeContextTemplate *context) const {
575+ (void )plan;
576+ (void )context;
577+ return true ;
578+ }
579+
580+ void NotNullLookupOnNotNullColumn::Transform (std::shared_ptr<AbsExpr_Expression> input,
581+ std::vector<std::shared_ptr<AbsExpr_Expression>> &transformed,
582+ OptimizeContextTemplate *context) const {
583+ (void )context;
584+ (void )transformed;
585+
586+ // Asserting guarantees provided by the GroupExprBindingIterator
587+ // Structure: (TRUE OR <any expression>)
588+ PELOTON_ASSERT (input->Children ().size () == 1 );
589+ PELOTON_ASSERT (input->Op ().GetType () == ExpressionType::OPERATOR_IS_NOT_NULL);
590+
591+ std::shared_ptr<AbsExpr_Expression> child = input->Children ()[0 ];
592+ PELOTON_ASSERT (child->Children ().size () == 0 );
593+ PELOTON_ASSERT (child->Op ().GetType () == ExpressionType::VALUE_TUPLE);
594+
595+ std::shared_ptr<expression::TupleValueExpression> tuple_expr = std::dynamic_pointer_cast<expression::TupleValueExpression>(child->Op ().GetExpr ());
596+
597+ // Only transform into [TRUE] if the tuple value expression is specifically non-NULL,
598+ // otherwise do nothing
599+ if (tuple_expr->GetIsNotNull ()) {
600+ type::Value val_true = type::ValueFactory::GetBooleanValue (true );
601+ std::shared_ptr<expression::ConstantValueExpression> true_expr = std::make_shared<expression::ConstantValueExpression>(val_true);
602+ std::shared_ptr<AbsExpr_Expression> true_container = std::make_shared<AbsExpr_Expression>(AbsExpr_Container (true_expr));
603+ transformed.push_back (true_container);
604+ }
605+ }
606+
512607} // namespace optimizer
513608} // namespace peloton
0 commit comments