Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring 2024: P3 Index Changes #702

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading