Skip to content

Commit

Permalink
Spring 2024: P3 Index Changes (#702)
Browse files Browse the repository at this point in the history
Updates index plan node and adds sqllogictests to be consistent with the new project specs.
  • Loading branch information
Sweetsuro committed Mar 12, 2024
1 parent 325775a commit bc3b742
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/include/execution/plans/index_scan_plan.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#include <string>
#include <utility>
#include <vector>

#include "catalog/catalog.h"
#include "concurrency/transaction.h"
#include "execution/expressions/abstract_expression.h"
#include "execution/expressions/constant_value_expression.h"
#include "execution/plans/abstract_plan.h"

namespace bustub {
Expand All @@ -35,12 +35,12 @@ class IndexScanPlanNode : public AbstractPlanNode {
* @param pred_key The key for point lookup
*/
IndexScanPlanNode(SchemaRef output, table_oid_t table_oid, index_oid_t index_oid,
AbstractExpressionRef filter_predicate = nullptr, ConstantValueExpression *pred_key = nullptr)
AbstractExpressionRef filter_predicate = nullptr, std::vector<AbstractExpressionRef> pred_keys = {})
: AbstractPlanNode(std::move(output), {}),
table_oid_(table_oid),
index_oid_(index_oid),
filter_predicate_(std::move(filter_predicate)),
pred_key_(pred_key) {}
pred_keys_(std::move(pred_keys)) {}

auto GetType() const -> PlanType override { return PlanType::IndexScan; }

Expand All @@ -62,10 +62,10 @@ class IndexScanPlanNode : public AbstractPlanNode {
AbstractExpressionRef filter_predicate_;

/**
* The constant value key to lookup.
* The constant value keys to lookup.
* For example when dealing "WHERE v = 1" we could store the constant value 1 here
*/
const ConstantValueExpression *pred_key_;
std::vector<AbstractExpressionRef> pred_keys_;

// Add anything you want here for index lookup

Expand Down
46 changes: 46 additions & 0 deletions test/sql/p3.05-index-scan.slt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ select * from t1 where v2 = 40;
----
2 40 721

statement ok
explain select * from t1 where v1 = 1 or v1 = 2;

query rowsort +ensure:index_scan
select * from t1 where v1 = 1 or v1 = 2;
----
1 50 645
2 40 721

query
select * from t1 where v1 = 1 and v2 = 50;
Expand Down Expand Up @@ -99,6 +107,12 @@ select * from t1 where v2 = 20;
----
4 20 445

query rowsort +ensure:index_scan
select * from t1 where v1 = 7 or 3 = v1;
----
7 -10 645
3 30 645

query +ensure:index_scan
select * from t1 where v2 = 40;
----
Expand Down Expand Up @@ -151,6 +165,38 @@ select * from t1 where v2 = 0 and v3 = 721;
----
6 0 721

query +ensure:seq_scan
select * from t1 where v1 = 7 or 10 = v2;
----
5 10 445
7 -10 645

query rowsort +ensure:index_scan
select * from t1 where v1 = 7 or v1 = 3 or 5 = v1;
----
7 -10 645
3 30 645
5 10 445

query +ensure:index_scan
select * from t1 where v1 = 3 or v1 = 3 or v1 = 3
----
3 30 645

query +ensure:index_scan
select * from t1 where v1 = 3 or v1 = 5 or v1 = 1 or v1 = 5
----
5 10 445
1 50 645
3 30 645

query +ensure:seq_scan
select * from t1 where v1 = 7 or v1 = 3 or 5 = v1 or 3 = v2;
----
5 10 445
3 30 645
7 -10 645

# Delete some elements
query
delete from t1 where v2 = 30;
Expand Down

0 comments on commit bc3b742

Please sign in to comment.