You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Helper functions for implementing the `Memoize` trait.
191
190
implSqliteMemo{
191
+
/// Gets the representative group id of a relational group.
192
192
asyncfnget_representative_group_id(
193
193
&self,
194
194
db:&mutSqliteConnection,
@@ -202,6 +202,7 @@ impl SqliteMemo {
202
202
Ok(representative_group_id)
203
203
}
204
204
205
+
/// Sets the representative group id of a relational group.
205
206
asyncfnset_representative_group_id(
206
207
&self,
207
208
db:&mutSqliteConnection,
@@ -216,6 +217,7 @@ impl SqliteMemo {
216
217
Ok(())
217
218
}
218
219
220
+
/// Gets the representative group id of a scalar group.
219
221
asyncfnget_representative_scalar_group_id(
220
222
&self,
221
223
db:&mutSqliteConnection,
@@ -229,6 +231,7 @@ impl SqliteMemo {
229
231
Ok(representative_group_id)
230
232
}
231
233
234
+
/// Sets the representative group id of a scalar group.
232
235
asyncfnset_representative_scalar_group_id(
233
236
&self,
234
237
db:&mutSqliteConnection,
@@ -243,6 +246,10 @@ impl SqliteMemo {
243
246
Ok(())
244
247
}
245
248
249
+
/// Inserts a scalar expression into the database. If the `add_to_group_id` is `Some`,
250
+
/// we will attempt to add the scalar expression to the specified group.
251
+
/// If the scalar expression already exists in the database, the existing group id will be returned.
252
+
/// Otherwise, a new group id will be created.
246
253
asyncfnadd_scalar_expr_to_group_inner(
247
254
&self,
248
255
scalar_expr:&ScalarExpression,
@@ -275,13 +282,13 @@ impl SqliteMemo {
275
282
ScalarOperatorKind::Constant,
276
283
)
277
284
.await?;
278
-
let group_id = sqlx::query_scalar("INSERT INTO scalar_constants (scalar_expression_id, group_id, value) VALUES ($1, $2, $3) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
285
+
286
+
sqlx::query_scalar("INSERT INTO scalar_constants (scalar_expression_id, group_id, value) VALUES ($1, $2, $3) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
279
287
.bind(scalar_expr_id)
280
288
.bind(group_id)
281
289
.bind(serde_json::to_string(&constant)?)
282
290
.fetch_one(&mut*txn)
283
-
.await?;
284
-
group_id
291
+
.await?
285
292
}
286
293
ScalarExpression::ColumnRef(column_ref) => {
287
294
Self::insert_into_scalar_expressions(
@@ -291,13 +298,13 @@ impl SqliteMemo {
291
298
ScalarOperatorKind::ColumnRef,
292
299
)
293
300
.await?;
294
-
let group_id = sqlx::query_scalar("INSERT INTO scalar_column_refs (scalar_expression_id, group_id, column_index) VALUES ($1, $2, $3) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
301
+
302
+
sqlx::query_scalar("INSERT INTO scalar_column_refs (scalar_expression_id, group_id, column_index) VALUES ($1, $2, $3) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
let group_id = sqlx::query_scalar("INSERT INTO scalar_adds (scalar_expression_id, group_id, left_group_id, right_group_id) VALUES ($1, $2, $3, $4) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
317
+
318
+
sqlx::query_scalar("INSERT INTO scalar_adds (scalar_expression_id, group_id, left_group_id, right_group_id) VALUES ($1, $2, $3, $4) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
314
319
.bind(scalar_expr_id)
315
320
.bind(group_id)
316
321
.bind(add.left)
317
322
.bind(add.right)
318
323
.fetch_one(&mut*txn)
319
-
.await?;
320
-
group_id
324
+
.await?
321
325
}
322
326
ScalarExpression::Equal(equal) => {
323
327
Self::insert_into_scalar_expressions(
@@ -327,14 +331,14 @@ impl SqliteMemo {
327
331
ScalarOperatorKind::Equal,
328
332
)
329
333
.await?;
330
-
let group_id = sqlx::query_scalar("INSERT INTO scalar_equals (scalar_expression_id, group_id, left_group_id, right_group_id) VALUES ($1, $2, $3, $4) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
334
+
335
+
sqlx::query_scalar("INSERT INTO scalar_equals (scalar_expression_id, group_id, left_group_id, right_group_id) VALUES ($1, $2, $3, $4) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
331
336
.bind(scalar_expr_id)
332
337
.bind(group_id)
333
338
.bind(equal.left)
334
339
.bind(equal.right)
335
340
.fetch_one(&mut*txn)
336
-
.await?;
337
-
group_id
341
+
.await?
338
342
}
339
343
};
340
344
@@ -354,7 +358,7 @@ impl SqliteMemo {
354
358
Ok(inserted_group_id)
355
359
}
356
360
357
-
/// Inserts a scalar expression into the database.
361
+
/// Inserts an entry into the `scalar_expressions` table.
358
362
asyncfninsert_into_scalar_expressions(
359
363
db:&mutSqliteConnection,
360
364
scalar_expr_id:ScalarExpressionId,
@@ -371,6 +375,7 @@ impl SqliteMemo {
371
375
Ok(())
372
376
}
373
377
378
+
/// Removes a dangling scalar expression from the `scalar_expressions` table.
374
379
asyncfnremove_dangling_scalar_expr(
375
380
&self,
376
381
db:&mutSqliteConnection,
@@ -383,6 +388,10 @@ impl SqliteMemo {
383
388
Ok(())
384
389
}
385
390
391
+
/// Inserts a logical expression into the memo table. If the `add_to_group_id` is `Some`,
392
+
/// we will attempt to add the logical expression to the specified group.
393
+
/// If the logical expression already exists in the database, the existing group id will be returned.
394
+
/// Otherwise, a new group id will be created.
386
395
asyncfnadd_logical_expr_to_group_inner(
387
396
&self,
388
397
logical_expr:&LogicalExpression,
@@ -417,14 +426,14 @@ impl SqliteMemo {
417
426
LogicalOperatorKind::Scan,
418
427
)
419
428
.await?;
420
-
let group_id= sqlx::query_scalar("INSERT INTO scans (logical_expression_id, group_id, table_name, predicate_group_id) VALUES ($1, $2, $3, $4) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
429
+
430
+
sqlx::query_scalar("INSERT INTO scans (logical_expression_id, group_id, table_name, predicate_group_id) VALUES ($1, $2, $3, $4) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
421
431
.bind(logical_expr_id)
422
432
.bind(group_id)
423
433
.bind(serde_json::to_string(&scan.table_name)?)
424
434
.bind(scan.predicate)
425
435
.fetch_one(&mut*txn)
426
-
.await?;
427
-
group_id
436
+
.await?
428
437
}
429
438
LogicalExpression::Filter(filter) => {
430
439
Self::insert_into_logical_expressions(
@@ -434,14 +443,14 @@ impl SqliteMemo {
434
443
LogicalOperatorKind::Filter,
435
444
)
436
445
.await?;
437
-
let group_id = sqlx::query_scalar("INSERT INTO filters (logical_expression_id, group_id, child_group_id, predicate_group_id) VALUES ($1, $2, $3, $4) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
446
+
447
+
sqlx::query_scalar("INSERT INTO filters (logical_expression_id, group_id, child_group_id, predicate_group_id) VALUES ($1, $2, $3, $4) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
438
448
.bind(logical_expr_id)
439
449
.bind(group_id)
440
450
.bind(filter.child)
441
451
.bind(filter.predicate)
442
452
.fetch_one(&mut*txn)
443
-
.await?;
444
-
group_id
453
+
.await?
445
454
}
446
455
LogicalExpression::Join(join) => {
447
456
Self::insert_into_logical_expressions(
@@ -451,16 +460,16 @@ impl SqliteMemo {
451
460
LogicalOperatorKind::Join,
452
461
)
453
462
.await?;
454
-
let group_id = sqlx::query_scalar("INSERT INTO joins (logical_expression_id, group_id, join_type, left_group_id, right_group_id, condition_group_id) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
463
+
464
+
sqlx::query_scalar("INSERT INTO joins (logical_expression_id, group_id, join_type, left_group_id, right_group_id, condition_group_id) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT DO UPDATE SET group_id = group_id RETURNING group_id")
455
465
.bind(logical_expr_id)
456
466
.bind(group_id)
457
467
.bind(serde_json::to_string(&join.join_type)?)
458
468
.bind(join.left)
459
469
.bind(join.right)
460
470
.bind(join.condition)
461
471
.fetch_one(&mut*txn)
462
-
.await?;
463
-
group_id
472
+
.await?
464
473
}
465
474
};
466
475
@@ -480,6 +489,7 @@ impl SqliteMemo {
480
489
Ok(inserted_group_id)
481
490
}
482
491
492
+
/// Inserts an entry into the `logical_expressions` table.
483
493
asyncfninsert_into_logical_expressions(
484
494
txn:&mutSqliteConnection,
485
495
logical_expr_id:LogicalExpressionId,
@@ -496,6 +506,7 @@ impl SqliteMemo {
496
506
Ok(())
497
507
}
498
508
509
+
/// Removes a dangling logical expression from the `logical_expressions` table.
499
510
asyncfnremove_dangling_logical_expr(
500
511
&self,
501
512
db:&mutSqliteConnection,
@@ -510,6 +521,8 @@ impl SqliteMemo {
510
521
}
511
522
512
523
/// The SQL query to get all logical expressions in a group.
524
+
/// For each of the operators, the logical_expression_id is selected,
"SELECT logical_expression_id, json_object('Scan', json_object('table_name', json(table_name), 'predicate', predicate_group_id)) as data FROM scans WHERE group_id = $1",
0 commit comments