1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#[allow(unused_imports)]
use std::{
arch::x86_64::{_mm_prefetch, _MM_HINT_T0},
fs::remove_file,
io::stdin,
};
#[allow(unused_imports)]
use rasterizeddb_core::{
core::{
column::Column, row::InsertOrUpdateRow, storage_providers::file_sync::LocalStorageProvider,
table::Table,
},
rql::parser::parse_rql,
EMPTY_BUFFER,
};
use stopwatch::Stopwatch;
#[tokio::main]
async fn main() -> std::io::Result<()> {
#[cfg(target_arch = "x86_64")]
{
let empty_buffer_ptr = EMPTY_BUFFER.as_ptr();
unsafe { _mm_prefetch::<_MM_HINT_T0>(empty_buffer_ptr as *const i8) };
}
std::env::set_var("RUST_BACKTRACE", "0");
//_ = remove_file("C:\\Users\\mspc6\\OneDrive\\Professional\\Desktop\\database.db");
let io_sync = LocalStorageProvider::new(
"C:\\Users\\mspc6\\OneDrive\\Professional\\Desktop",
"database.db",
)
.await;
//let io_sync = MemoryStorageProvider::new();
//let database = Database::new(io_sync).await?;
// Database::start_async(Arc::new(RwLock::new(database))).await?;
// loop {
// tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
// }
//let io_sync = MemoryStorageProvider::new();
let mut table = Table::init(io_sync, false, false).await.unwrap();
for i in 200_000..=1_000_000 {
let c1 = Column::new(i).unwrap();
let c2 = Column::new(i * -1).unwrap();
let str = 'A'.to_string().repeat(100);
let c3 = Column::new(str).unwrap();
let mut columns_buffer: Vec<u8> = Vec::with_capacity(
c1.len() +
c2.len() +
c3.len()
);
columns_buffer.append(&mut c1.content.to_vec());
columns_buffer.append(&mut c2.content.to_vec());
columns_buffer.append(&mut c3.content.to_vec());
let _insert_row = InsertOrUpdateRow {
columns_data: columns_buffer.clone()
};
table.insert_row_unsync(_insert_row).await;
}
println!("DONE inserting rows.");
table.rebuild_in_memory_indexes().await;
println!("DONE building indexes.");
println!("Press any key to continue...");
let mut buffer = String::new();
stdin().read_line(&mut buffer).unwrap();
let mut stopwatch = Stopwatch::new();
let query_evaluation = parse_rql(&format!(
r#"
BEGIN
SELECT FROM NAME_DOESNT_MATTER_FOR_NOW
WHERE COL(0) > 999872
LIMIT 2
END
"#
))
.unwrap();
stopwatch.start();
let rows = table.execute_query(query_evaluation.parser_result).await?;
stopwatch.stop();
println!("elapsed {:?}", stopwatch.elapsed());
println!("total rows {:?}", rows.unwrap().len());
println!("second try");
stopwatch.reset();
let query_evaluation = parse_rql(&format!(
r#"
BEGIN
SELECT FROM NAME_DOESNT_MATTER_FOR_NOW
WHERE COL(0) > 999872
LIMIT 2
END
"#
))
.unwrap();
stopwatch.start();
let rows = table.execute_query(query_evaluation.parser_result).await?;
stopwatch.stop();
println!("elapsed {:?}", stopwatch.elapsed());
println!("total rows {:?}", rows.unwrap().len());
//table.delete_row_by_id(3).await.unwrap();
// UPDATE ROW(3)
//let x = 48;
//let mut c1_update = Column::new(21).unwrap();
//let mut c2_update = Column::new(x * -1).unwrap();
//let large_string = "A".repeat(1024);
//let mut c3_update = Column::new(&large_string).unwrap();
// let mut columns_buffer_update: Vec<u8> = Vec::with_capacity(
// c1_update.len() +
// c2_update.len()
//c3_update.len()
//);
// columns_buffer_update.append(&mut c1_update.into_vec().unwrap());
// columns_buffer_update.append(&mut c2_update.into_vec().unwrap());
//columns_buffer_update.append(&mut c3_update.into_vec().unwrap());
// let update_row = InsertOrUpdateRow {
// columns_data: columns_buffer_update
// };
//table.update_row_by_id(3, update_row).await;
//table.delete_row_by_id(3).unwrap();
//table.vacuum_table().await;
//table.first_or_default_by_id(3)?.unwrap();
// END UPDATE ROW(3)
//let row = table.first_or_default_by_id(4).await?.unwrap();
// for column in Column::from_buffer(&row.columns_data).unwrap() {
// println!("{}", column.into_value());
// }
//let row = table.first_or_default_by_column(0, 21)?.unwrap();
// for column in Column::from_buffer(&row.columns_data).unwrap() {
// println!("{}", column.into_value());
// }
// let mut stopwatch = Stopwatch::new();
// for _ in 0..100 {
// stopwatch.start();
// let query_evaluation = parse_rql(&format!(r#"
// BEGIN
// SELECT FROM NAME_DOESNT_MATTER_FOR_NOW
// WHERE COL(0) >= 0 LIMIT 20
// END
// "#)).unwrap();
// //let _rows = table.execute_query(query_evaluation).await?.unwrap();
// stopwatch.stop();
// println!("{}ms", stopwatch.elapsed_ms());
// stopwatch.reset();
// println!("DONE");
// }
// for row in rows {
// for column in Column::from_buffer(&row.columns_data).unwrap() {
// println!("{}", column.into_value());
// }
// }
println!("Press any key to continue...");
let mut buffer = String::new();
stdin().read_line(&mut buffer).unwrap();
Ok(())
}