Skip to content

Commit 4013547

Browse files
committed
refactor: enumerate the childrens attribute of LogicalPlan
1 parent 04b4a70 commit 4013547

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+419
-300
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[package]
44
name = "fnck_sql"
5-
version = "0.0.6"
5+
version = "0.0.7"
66
edition = "2021"
77
authors = ["Kould <[email protected]>", "Xwg <[email protected]>"]
88
description = "SQL as a Function for Rust"

benchmarks/query_benchmark.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ fn query_cases() -> Vec<(&'static str, &'static str)> {
2525
}
2626

2727
fn init_fncksql_query_bench() -> Result<(), DatabaseError> {
28-
let database = DataBaseBuilder::path(QUERY_BENCH_FNCK_SQL_PATH)
29-
.build()?;
30-
database.run("create table t1 (c1 int primary key, c2 int)")?.done()?;
28+
let database = DataBaseBuilder::path(QUERY_BENCH_FNCK_SQL_PATH).build()?;
29+
database
30+
.run("create table t1 (c1 int primary key, c2 int)")?
31+
.done()?;
3132
let pb = ProgressBar::new(TABLE_ROW_NUM);
3233
pb.set_style(
3334
ProgressStyle::default_bar()
3435
.template("[{elapsed_precise}] {bar:40.cyan/white} {pos}/{len} {msg}")
3536
.unwrap(),
3637
);
3738
for i in 0..TABLE_ROW_NUM {
38-
database.run(format!("insert into t1 values({}, {})", i, i + 1).as_str())?.done()?;
39+
database
40+
.run(format!("insert into t1 values({}, {})", i, i + 1).as_str())?
41+
.done()?;
3942
pb.set_position(i + 1);
4043
}
4144
pb.finish_with_message("Insert completed!");
@@ -106,9 +109,7 @@ fn query_on_execute(c: &mut Criterion) {
106109
let connection = sqlite::open(QUERY_BENCH_SQLITE_PATH.to_owned()).unwrap();
107110
c.bench_function(format!("SQLite: {} by '{}'", name, case).as_str(), |b| {
108111
b.iter(|| {
109-
for row in connection
110-
.prepare(case)
111-
.unwrap() {
112+
for row in connection.prepare(case).unwrap() {
112113
let _ = row.unwrap();
113114
}
114115
})

src/bin/server.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,12 @@ impl SimpleQueryHandler for SessionBackend {
173173
let mut guard = self.tx.lock();
174174

175175
let iter = if let Some(transaction) = guard.as_mut() {
176-
unsafe { transaction.as_mut().run(query) }.map(Box::new) as Result<Box<dyn ResultIter>, _>
176+
unsafe { transaction.as_mut().run(query) }.map(Box::new)
177+
as Result<Box<dyn ResultIter>, _>
177178
} else {
178179
self.inner.run(query).map(Box::new)
179-
}.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
180+
}
181+
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
180182

181183
let mut tuples = Vec::new();
182184
for tuple in iter {

src/binder/alter_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::planner::operator::alter_table::add_column::AddColumnOperator;
99
use crate::planner::operator::alter_table::drop_column::DropColumnOperator;
1010
use crate::planner::operator::table_scan::TableScanOperator;
1111
use crate::planner::operator::Operator;
12-
use crate::planner::LogicalPlan;
12+
use crate::planner::{Childrens, LogicalPlan};
1313
use crate::storage::Transaction;
1414

1515
impl<T: Transaction> Binder<'_, '_, T> {
@@ -43,7 +43,7 @@ impl<T: Transaction> Binder<'_, '_, T> {
4343
if_not_exists: *if_not_exists,
4444
column,
4545
}),
46-
vec![plan],
46+
Childrens::Only(plan),
4747
)
4848
}
4949
AlterTableOperation::DropColumn {
@@ -60,7 +60,7 @@ impl<T: Transaction> Binder<'_, '_, T> {
6060
if_exists: *if_exists,
6161
column_name,
6262
}),
63-
vec![plan],
63+
Childrens::Only(plan),
6464
)
6565
}
6666
AlterTableOperation::DropPrimaryKey => todo!(),

src/binder/analyze.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::errors::DatabaseError;
33
use crate::planner::operator::analyze::AnalyzeOperator;
44
use crate::planner::operator::table_scan::TableScanOperator;
55
use crate::planner::operator::Operator;
6-
use crate::planner::LogicalPlan;
6+
use crate::planner::{Childrens, LogicalPlan};
77
use crate::storage::Transaction;
88
use sqlparser::ast::ObjectName;
99
use std::sync::Arc;
@@ -31,7 +31,7 @@ impl<T: Transaction> Binder<'_, '_, T> {
3131
table_name,
3232
index_metas,
3333
}),
34-
vec![scan_op],
34+
Childrens::Only(scan_op),
3535
))
3636
}
3737
}

src/binder/copy.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::errors::DatabaseError;
77
use crate::planner::operator::copy_from_file::CopyFromFileOperator;
88
use crate::planner::operator::copy_to_file::CopyToFileOperator;
99
use crate::planner::operator::Operator;
10+
use crate::planner::Childrens;
1011
use fnck_sql_serde_macros::ReferenceSerialization;
1112
use serde::{Deserialize, Serialize};
1213
use sqlparser::ast::{CopyOption, CopySource, CopyTarget};
@@ -98,7 +99,7 @@ impl<T: Transaction> Binder<'_, '_, T> {
9899
target: ext_source,
99100
schema_ref,
100101
}),
101-
vec![],
102+
Childrens::None,
102103
))
103104
} else {
104105
// COPY <dest_table> FROM <source_file>
@@ -108,7 +109,7 @@ impl<T: Transaction> Binder<'_, '_, T> {
108109
schema_ref,
109110
table: table_name.to_string(),
110111
}),
111-
vec![],
112+
Childrens::None,
112113
))
113114
}
114115
} else {

src/binder/create_index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::expression::ScalarExpression;
44
use crate::planner::operator::create_index::CreateIndexOperator;
55
use crate::planner::operator::table_scan::TableScanOperator;
66
use crate::planner::operator::Operator;
7-
use crate::planner::LogicalPlan;
7+
use crate::planner::{Childrens, LogicalPlan};
88
use crate::storage::Transaction;
99
use crate::types::index::IndexType;
1010
use sqlparser::ast::{ObjectName, OrderByExpr};
@@ -60,7 +60,7 @@ impl<T: Transaction> Binder<'_, '_, T> {
6060
if_not_exists,
6161
ty,
6262
}),
63-
vec![plan],
63+
Childrens::Only(plan),
6464
))
6565
}
6666
}

src/binder/create_table.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::errors::DatabaseError;
1010
use crate::expression::ScalarExpression;
1111
use crate::planner::operator::create_table::CreateTableOperator;
1212
use crate::planner::operator::Operator;
13-
use crate::planner::LogicalPlan;
13+
use crate::planner::{Childrens, LogicalPlan};
1414
use crate::storage::Transaction;
1515
use crate::types::LogicalType;
1616

@@ -90,7 +90,7 @@ impl<T: Transaction> Binder<'_, '_, T> {
9090
columns,
9191
if_not_exists,
9292
}),
93-
vec![],
93+
Childrens::None,
9494
))
9595
}
9696

src/binder/create_view.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::errors::DatabaseError;
55
use crate::expression::{AliasType, ScalarExpression};
66
use crate::planner::operator::create_view::CreateViewOperator;
77
use crate::planner::operator::Operator;
8-
use crate::planner::LogicalPlan;
8+
use crate::planner::{Childrens, LogicalPlan};
99
use crate::storage::Transaction;
1010
use itertools::Itertools;
1111
use sqlparser::ast::{Ident, ObjectName, Query};
@@ -56,7 +56,7 @@ impl<T: Transaction> Binder<'_, '_, T> {
5656
},
5757
or_replace: *or_replace,
5858
}),
59-
vec![],
59+
Childrens::None,
6060
))
6161
}
6262
}

src/binder/delete.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::errors::DatabaseError;
33
use crate::planner::operator::delete::DeleteOperator;
44
use crate::planner::operator::table_scan::TableScanOperator;
55
use crate::planner::operator::Operator;
6-
use crate::planner::LogicalPlan;
6+
use crate::planner::{Childrens, LogicalPlan};
77
use crate::storage::Transaction;
88
use itertools::Itertools;
99
use sqlparser::ast::{Expr, TableAlias, TableFactor, TableWithJoins};
@@ -52,7 +52,7 @@ impl<T: Transaction> Binder<'_, '_, T> {
5252
table_name,
5353
primary_keys,
5454
}),
55-
vec![plan],
55+
Childrens::Only(plan),
5656
))
5757
} else {
5858
unreachable!("only table")

0 commit comments

Comments
 (0)