1#include "catch.hpp"
2#include "duckdb/common/helper.hpp"
3#include "expression_helper.hpp"
4#include "duckdb/optimizer/index_scan.hpp"
5#include "duckdb/planner/expression/bound_comparison_expression.hpp"
6#include "duckdb/planner/expression/bound_operator_expression.hpp"
7#include "duckdb/planner/expression/common_subexpression.hpp"
8#include "test_helpers.hpp"
9
10using namespace duckdb;
11using namespace std;
12
13TEST_CASE("Test Index Scan Optimizer for Integers", "[index-optimizer]") {
14 ExpressionHelper helper;
15 auto &con = helper.con;
16 string int_types[1] = {"integer"}; // {"tinyint", "smallint", "integer", "bigint"};
17
18 for (int idx = 0; idx < 1; idx++) {
19 REQUIRE_NO_FAIL(con.Query("CREATE TABLE integers(i " + int_types[idx] + ")"));
20 //! Checking Order Index
21 con.Query("CREATE INDEX i_index ON integers(i)");
22 // Checking if Optimizer is using index in simple case
23 auto tree = helper.ParseLogicalTree("SELECT i FROM integers where i > CAST(10 AS " + int_types[idx] + ")");
24 IndexScan index_scan;
25 auto plan = index_scan.Optimize(move(tree));
26 REQUIRE(plan->children[0]->type == LogicalOperatorType::FILTER);
27 REQUIRE(plan->children[0]->children[0]->type == LogicalOperatorType::INDEX_SCAN);
28 con.Query("DROP INDEX i_index");
29 }
30}
31
32// FIXME: These tests make no sense with the current matching system
33// Write proper tests after reworking optimization
34
35// TEST_CASE("Test Index Scan Optimizer for Floats", "[index-optimizer-float]") {
36// ExpressionHelper helper;
37// auto &con = helper.con;
38// string int_types[2] = {"real","double"}; // {"tinyint", "smallint", "integer", "bigint"};
39//
40// for (int idx = 0; idx < 1; idx++) {
41// REQUIRE_NO_FAIL(con.Query("CREATE TABLE integers(i " + int_types[idx] + ")"));
42// //! Checking Order Index
43// con.Query("CREATE INDEX i_index ON integers(i)");
44// // Checking if Optimizer is using index in simple case
45// auto tree = helper.ParseLogicalTree("SELECT i FROM integers where i > CAST(10 AS " + int_types[idx] + ")");
46// IndexScan index_scan;
47// auto plan = index_scan.Optimize(move(tree));
48// REQUIRE(plan->children[0]->type == LogicalOperatorType::FILTER);
49// REQUIRE(plan->children[0]->children[0]->type == LogicalOperatorType::INDEX_SCAN);
50// con.Query("DROP INDEX i_index");
51// }
52//}
53//
54// TEST_CASE("Test Index Scan Optimizer for Strings", "[index-optimizer-string]") {
55// ExpressionHelper helper;
56// auto &con = helper.con;
57//
58// REQUIRE_NO_FAIL(con.Query("CREATE TABLE strings(i varchar)"));
59// //! Checking Order Index
60// con.Query("CREATE INDEX i_index ON strings(i)");
61// // Checking if Optimizer is using index in simple case
62// auto tree = helper.ParseLogicalTree("SELECT i FROM strings where i >= 'testa' AND i <= 'testz'");
63// IndexScan index_scan;
64// auto plan = index_scan.Optimize(move(tree));
65// REQUIRE(plan->children[0]->type == LogicalOperatorType::FILTER);
66// REQUIRE(plan->children[0]->children[0]->type == LogicalOperatorType::INDEX_SCAN);
67// con.Query("DROP INDEX i_index");
68//}
69