duckdb 0.3.5-dev387.0 → 0.3.5-dev394.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.3.5-dev387.0",
4
+ "version": "0.3.5-dev394.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -132513,6 +132513,32 @@ public:
132513
132513
 
132514
132514
 
132515
132515
 
132516
+ //===----------------------------------------------------------------------===//
132517
+ // DuckDB
132518
+ //
132519
+ // duckdb/optimizer/rule/equal_or_null_simplification.hpp
132520
+ //
132521
+ //
132522
+ //===----------------------------------------------------------------------===//
132523
+
132524
+
132525
+
132526
+
132527
+
132528
+ namespace duckdb {
132529
+
132530
+ // Rewrite
132531
+ // a=b OR (a IS NULL AND b IS NULL) to a IS NOT DISTINCT FROM b
132532
+ class EqualOrNullSimplification : public Rule {
132533
+ public:
132534
+ explicit EqualOrNullSimplification(ExpressionRewriter &rewriter);
132535
+
132536
+ unique_ptr<Expression> Apply(LogicalOperator &op, vector<Expression *> &bindings, bool &changes_made,
132537
+ bool is_root) override;
132538
+ };
132539
+
132540
+ } // namespace duckdb
132541
+
132516
132542
  //===----------------------------------------------------------------------===//
132517
132543
  // DuckDB
132518
132544
  //
@@ -132550,6 +132576,7 @@ Optimizer::Optimizer(Binder &binder, ClientContext &context) : context(context),
132550
132576
  rewriter.rules.push_back(make_unique<DatePartSimplificationRule>(rewriter));
132551
132577
  rewriter.rules.push_back(make_unique<ComparisonSimplificationRule>(rewriter));
132552
132578
  rewriter.rules.push_back(make_unique<InClauseSimplificationRule>(rewriter));
132579
+ rewriter.rules.push_back(make_unique<EqualOrNullSimplification>(rewriter));
132553
132580
  rewriter.rules.push_back(make_unique<MoveConstantsRule>(rewriter));
132554
132581
  rewriter.rules.push_back(make_unique<LikeOptimizationRule>(rewriter));
132555
132582
  rewriter.rules.push_back(make_unique<EmptyNeedleRemovalRule>(rewriter));
@@ -134543,6 +134570,118 @@ unique_ptr<Expression> EnumComparisonRule::Apply(LogicalOperator &op, vector<Exp
134543
134570
 
134544
134571
 
134545
134572
 
134573
+
134574
+ namespace duckdb {
134575
+
134576
+ EqualOrNullSimplification::EqualOrNullSimplification(ExpressionRewriter &rewriter) : Rule(rewriter) {
134577
+ // match on OR conjunction
134578
+ auto op = make_unique<ConjunctionExpressionMatcher>();
134579
+ op->expr_type = make_unique<SpecificExpressionTypeMatcher>(ExpressionType::CONJUNCTION_OR);
134580
+ op->policy = SetMatcher::Policy::SOME;
134581
+
134582
+ // equi comparison on one side
134583
+ auto equal_child = make_unique<ComparisonExpressionMatcher>();
134584
+ equal_child->expr_type = make_unique<SpecificExpressionTypeMatcher>(ExpressionType::COMPARE_EQUAL);
134585
+ equal_child->policy = SetMatcher::Policy::SOME;
134586
+ op->matchers.push_back(move(equal_child));
134587
+
134588
+ // AND conjuction on the other
134589
+ auto and_child = make_unique<ConjunctionExpressionMatcher>();
134590
+ and_child->expr_type = make_unique<SpecificExpressionTypeMatcher>(ExpressionType::CONJUNCTION_AND);
134591
+ and_child->policy = SetMatcher::Policy::SOME;
134592
+
134593
+ // IS NULL tests inside AND
134594
+ auto isnull_child = make_unique<ExpressionMatcher>();
134595
+ isnull_child->expr_type = make_unique<SpecificExpressionTypeMatcher>(ExpressionType::OPERATOR_IS_NULL);
134596
+ // I could try to use std::make_unique for a copy, but it's available from C++14 only
134597
+ auto isnull_child2 = make_unique<ExpressionMatcher>();
134598
+ isnull_child2->expr_type = make_unique<SpecificExpressionTypeMatcher>(ExpressionType::OPERATOR_IS_NULL);
134599
+ and_child->matchers.push_back(move(isnull_child));
134600
+ and_child->matchers.push_back(move(isnull_child2));
134601
+
134602
+ op->matchers.push_back(move(and_child));
134603
+ root = move(op);
134604
+ }
134605
+
134606
+ // a=b OR (a IS NULL AND b IS NULL) to a IS NOT DISTINCT FROM b
134607
+ static unique_ptr<Expression> TryRewriteEqualOrIsNull(const Expression *equal_expr, const Expression *and_expr) {
134608
+ if (equal_expr->type != ExpressionType::COMPARE_EQUAL || and_expr->type != ExpressionType::CONJUNCTION_AND) {
134609
+ return nullptr;
134610
+ }
134611
+
134612
+ const auto equal_cast = (BoundComparisonExpression *)equal_expr;
134613
+ const auto and_cast = (BoundConjunctionExpression *)and_expr;
134614
+
134615
+ if (and_cast->children.size() != 2) {
134616
+ return nullptr;
134617
+ }
134618
+
134619
+ // Make sure on the AND conjuction the relevant conditions appear
134620
+ const auto a_exp = equal_cast->left.get();
134621
+ const auto b_exp = equal_cast->right.get();
134622
+ bool valid = true;
134623
+ bool a_is_null_found = false;
134624
+ bool b_is_null_found = false;
134625
+
134626
+ for (const auto &item : and_cast->children) {
134627
+ const auto next_exp = item.get();
134628
+
134629
+ if (next_exp->type == ExpressionType::OPERATOR_IS_NULL) {
134630
+ const auto next_exp_cast = (BoundOperatorExpression *)next_exp;
134631
+ const auto child = next_exp_cast->children[0].get();
134632
+
134633
+ // Test for equality on both 'a' and 'b' expressions
134634
+ if (Expression::Equals(child, a_exp)) {
134635
+ a_is_null_found = true;
134636
+ } else if (Expression::Equals(child, b_exp)) {
134637
+ b_is_null_found = true;
134638
+ } else {
134639
+ valid = false;
134640
+ break;
134641
+ }
134642
+ } else {
134643
+ valid = false;
134644
+ break;
134645
+ }
134646
+ }
134647
+ if (valid && a_is_null_found && b_is_null_found) {
134648
+ return make_unique<BoundComparisonExpression>(ExpressionType::COMPARE_NOT_DISTINCT_FROM, move(equal_cast->left),
134649
+ move(equal_cast->right));
134650
+ }
134651
+ return nullptr;
134652
+ }
134653
+
134654
+ unique_ptr<Expression> EqualOrNullSimplification::Apply(LogicalOperator &op, vector<Expression *> &bindings,
134655
+ bool &changes_made, bool is_root) {
134656
+ const Expression *or_exp = bindings[0];
134657
+
134658
+ if (or_exp->type != ExpressionType::CONJUNCTION_OR) {
134659
+ return nullptr;
134660
+ }
134661
+
134662
+ const auto or_exp_cast = (BoundConjunctionExpression *)or_exp;
134663
+
134664
+ if (or_exp_cast->children.size() != 2) {
134665
+ return nullptr;
134666
+ }
134667
+
134668
+ const auto left_exp = or_exp_cast->children[0].get();
134669
+ const auto right_exp = or_exp_cast->children[1].get();
134670
+ // Test for: a=b OR (a IS NULL AND b IS NULL)
134671
+ auto first_try = TryRewriteEqualOrIsNull(left_exp, right_exp);
134672
+ if (first_try) {
134673
+ return first_try;
134674
+ }
134675
+ // Test for: (a IS NULL AND b IS NULL) OR a=b
134676
+ return TryRewriteEqualOrIsNull(right_exp, left_exp);
134677
+ }
134678
+
134679
+ } // namespace duckdb
134680
+
134681
+
134682
+
134683
+
134684
+
134546
134685
  namespace duckdb {
134547
134686
 
134548
134687
  InClauseSimplificationRule::InClauseSimplificationRule(ExpressionRewriter &rewriter) : Rule(rewriter) {
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "1bcd8a31c"
15
- #define DUCKDB_VERSION "v0.3.5-dev387"
14
+ #define DUCKDB_SOURCE_ID "2311f7eb0"
15
+ #define DUCKDB_VERSION "v0.3.5-dev394"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //