Skip to content
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
20 changes: 19 additions & 1 deletion e2e_test/batch/basic/index.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,22 @@ select * from t where lower(v1) = 'hello';
Hello World

statement ok
drop table t;
drop table t;

# indexes on expressions
statement ok
create table people (first_name varchar, last_name varchar, info varchar);

statement ok
create index people_names ON people ((first_name || ' ' || last_name));

statement ok
insert into people values ('John', 'Smith', 'test'), ('Dylan', 'Chen', 'test');

query TTT
select * from people where (first_name || ' ' || last_name) = 'John Smith';;
----
John Smith test

statement ok
drop table people;
7 changes: 7 additions & 0 deletions src/frontend/planner_test/tests/testdata/index_selection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -703,3 +703,10 @@
| └─BatchScan { table: idx1, columns: [idx1.t._row_id], scan_ranges: [idx1.JSONB_ACCESS_STR = Utf8("abc")], distribution: SomeShard }
└─BatchExchange { order: [], dist: Single }
└─BatchScan { table: idx2, columns: [idx2.t._row_id], scan_ranges: [idx2.JSONB_ACCESS_STR = Utf8("ABC")], distribution: SomeShard }
- sql: |
create table people (first_name varchar, last_name varchar, info varchar);
create index people_names ON people ((first_name || ' ' || last_name));
select * from people where (first_name || ' ' || last_name) = 'John Smith';
batch_plan: |
BatchExchange { order: [], dist: Single }
└─BatchScan { table: people_names, columns: [people_names.first_name, people_names.last_name, people_names.info], scan_ranges: [people_names.CONCAT_OP = Utf8("John Smith")], distribution: SomeShard }
34 changes: 9 additions & 25 deletions src/frontend/src/handler/create_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use risingwave_sqlparser::ast::{Ident, ObjectName, OrderByExpr};
use super::RwPgResponse;
use crate::binder::Binder;
use crate::catalog::root_catalog::SchemaPath;
use crate::expr::{Expr, ExprImpl, ExprType, InputRef};
use crate::expr::{Expr, ExprImpl, InputRef};
use crate::handler::privilege::ObjectCheckItem;
use crate::handler::HandlerArgs;
use crate::optimizer::plan_node::{Explain, LogicalProject, LogicalScan, StreamMaterialize};
Expand Down Expand Up @@ -85,41 +85,25 @@ pub(crate) fn gen_create_index_plan(
for column in columns {
let order_type = OrderType::from_bools(column.asc, column.nulls_first);
let expr_impl = binder.bind_expr(column.expr)?;
match &expr_impl {
match expr_impl {
ExprImpl::InputRef(_) => {}
ExprImpl::FunctionCall(func) => {
match func.get_expr_type() {
// TODO: support more functions after verification
ExprType::Lower
| ExprType::Upper
| ExprType::JsonbAccessInner
| ExprType::JsonbAccessStr => {}
_ => {
return Err(ErrorCode::NotSupported(
"this function is not supported for indexes".into(),
"use other functions instead".into(),
)
.into())
}
};
if !func.inputs().iter().all(|input| {
matches!(input, ExprImpl::InputRef(_)) || matches!(input, ExprImpl::Literal(_))
}) {
ExprImpl::FunctionCall(_) => {
if expr_impl.is_impure() {
return Err(ErrorCode::NotSupported(
"complex arguments for functions are not supported".into(),
"use columns or literals instead".into(),
"this expression is impure".into(),
"use a pure expression instead".into(),
)
.into());
}
}
_ => {
return Err(ErrorCode::NotSupported(
"index columns should be columns or functions".into(),
"use columns or functions instead".into(),
"index columns should be columns or expressions".into(),
"use columns or expressions instead".into(),
)
.into())
}
};
}
index_columns_ordered_expr.push((expr_impl, order_type));
}

Expand Down