stoolap 0.4.0

High-performance embedded SQL database with MVCC, time-travel queries, and full ACID compliance
Documentation
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
// Copyright 2025 Stoolap Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Tests for index optimizer functionality
//!
//! Tests MIN/MAX index optimization, COUNT(*) optimization, keyset pagination,
//! IN list/subquery index probing, and ORDER BY index optimization.

use stoolap::Database;

fn setup_indexed_table(db: &Database) {
    db.execute(
        "CREATE TABLE products (
            id INTEGER PRIMARY KEY,
            name TEXT,
            price FLOAT,
            category TEXT,
            stock INTEGER
        )",
        (),
    )
    .expect("Failed to create table");

    // Create indexes
    db.execute("CREATE INDEX idx_price ON products(price)", ())
        .expect("Failed to create price index");
    db.execute("CREATE INDEX idx_category ON products(category)", ())
        .expect("Failed to create category index");
    db.execute("CREATE INDEX idx_stock ON products(stock)", ())
        .expect("Failed to create stock index");

    // Insert test data
    let inserts = [
        "INSERT INTO products VALUES (1, 'Laptop', 999.99, 'Electronics', 50)",
        "INSERT INTO products VALUES (2, 'Phone', 599.99, 'Electronics', 100)",
        "INSERT INTO products VALUES (3, 'Tablet', 399.99, 'Electronics', 75)",
        "INSERT INTO products VALUES (4, 'Chair', 149.99, 'Furniture', 200)",
        "INSERT INTO products VALUES (5, 'Desk', 299.99, 'Furniture', 30)",
        "INSERT INTO products VALUES (6, 'Lamp', 49.99, 'Furniture', 150)",
        "INSERT INTO products VALUES (7, 'Book', 19.99, 'Books', 500)",
        "INSERT INTO products VALUES (8, 'Notebook', 9.99, 'Books', 1000)",
        "INSERT INTO products VALUES (9, 'Pen', 4.99, 'Books', 2000)",
        "INSERT INTO products VALUES (10, 'Monitor', 349.99, 'Electronics', 40)",
    ];

    for insert in &inserts {
        db.execute(insert, ()).expect("Failed to insert data");
    }
}

// =============================================================================
// MIN/MAX Index Optimization Tests
// =============================================================================

#[test]
fn test_min_on_indexed_column() {
    let db = Database::open("memory://min_indexed").expect("Failed to create database");
    setup_indexed_table(&db);

    let min_price: f64 = db
        .query_one("SELECT MIN(price) FROM products", ())
        .expect("Failed to query MIN");

    assert!(
        (min_price - 4.99).abs() < 0.01,
        "Expected MIN(price) = 4.99, got {}",
        min_price
    );
}

#[test]
fn test_max_on_indexed_column() {
    let db = Database::open("memory://max_indexed").expect("Failed to create database");
    setup_indexed_table(&db);

    let max_price: f64 = db
        .query_one("SELECT MAX(price) FROM products", ())
        .expect("Failed to query MAX");

    assert!(
        (max_price - 999.99).abs() < 0.01,
        "Expected MAX(price) = 999.99, got {}",
        max_price
    );
}

#[test]
fn test_min_with_alias() {
    let db = Database::open("memory://min_alias").expect("Failed to create database");
    setup_indexed_table(&db);

    let result = db
        .query("SELECT MIN(price) AS min_price FROM products", ())
        .expect("Failed to query");

    let columns = result.columns().to_vec();
    assert_eq!(columns[0], "min_price", "Expected alias 'min_price'");
}

#[test]
fn test_max_with_alias() {
    let db = Database::open("memory://max_alias").expect("Failed to create database");
    setup_indexed_table(&db);

    let result = db
        .query("SELECT MAX(price) AS max_price FROM products", ())
        .expect("Failed to query");

    let columns = result.columns().to_vec();
    assert_eq!(columns[0], "max_price", "Expected alias 'max_price'");
}

#[test]
fn test_min_on_integer_column() {
    let db = Database::open("memory://min_integer").expect("Failed to create database");
    setup_indexed_table(&db);

    let min_stock: i64 = db
        .query_one("SELECT MIN(stock) FROM products", ())
        .expect("Failed to query MIN");

    assert_eq!(min_stock, 30, "Expected MIN(stock) = 30");
}

#[test]
fn test_max_on_integer_column() {
    let db = Database::open("memory://max_integer").expect("Failed to create database");
    setup_indexed_table(&db);

    let max_stock: i64 = db
        .query_one("SELECT MAX(stock) FROM products", ())
        .expect("Failed to query MAX");

    assert_eq!(max_stock, 2000, "Expected MAX(stock) = 2000");
}

// =============================================================================
// COUNT(*) Optimization Tests
// =============================================================================

#[test]
fn test_count_star_optimization() {
    let db = Database::open("memory://count_star").expect("Failed to create database");
    setup_indexed_table(&db);

    let count: i64 = db
        .query_one("SELECT COUNT(*) FROM products", ())
        .expect("Failed to query COUNT");

    assert_eq!(count, 10, "Expected COUNT(*) = 10");
}

#[test]
fn test_count_star_with_alias() {
    let db = Database::open("memory://count_star_alias").expect("Failed to create database");
    setup_indexed_table(&db);

    let result = db
        .query("SELECT COUNT(*) AS total FROM products", ())
        .expect("Failed to query");

    let columns = result.columns().to_vec();
    assert_eq!(columns[0], "total", "Expected alias 'total'");
}

// =============================================================================
// Keyset Pagination Tests (id > X ORDER BY id LIMIT Y)
// =============================================================================

#[test]
fn test_keyset_pagination_basic() {
    let db = Database::open("memory://keyset_basic").expect("Failed to create database");
    setup_indexed_table(&db);

    // Get products with id > 5, ordered by id, limit 3
    let result = db
        .query(
            "SELECT id, name FROM products WHERE id > 5 ORDER BY id LIMIT 3",
            (),
        )
        .expect("Failed to query");

    let mut ids = Vec::new();
    for row in result {
        let row = row.expect("Failed to get row");
        let id: i64 = row.get(0).unwrap();
        ids.push(id);
    }

    assert_eq!(ids, vec![6, 7, 8], "Expected ids [6, 7, 8]");
}

#[test]
fn test_keyset_pagination_gte() {
    let db = Database::open("memory://keyset_gte").expect("Failed to create database");
    setup_indexed_table(&db);

    // Get products with id >= 8, ordered by id, limit 5
    let result = db
        .query(
            "SELECT id FROM products WHERE id >= 8 ORDER BY id LIMIT 5",
            (),
        )
        .expect("Failed to query");

    let mut ids = Vec::new();
    for row in result {
        let row = row.expect("Failed to get row");
        let id: i64 = row.get(0).unwrap();
        ids.push(id);
    }

    assert_eq!(ids, vec![8, 9, 10], "Expected ids [8, 9, 10]");
}

#[test]
fn test_keyset_pagination_reversed_comparison() {
    let db = Database::open("memory://keyset_reversed").expect("Failed to create database");
    setup_indexed_table(&db);

    // Test reversed comparison: 3 < id (same as id > 3)
    let result = db
        .query(
            "SELECT id FROM products WHERE 3 < id ORDER BY id LIMIT 3",
            (),
        )
        .expect("Failed to query");

    let mut ids = Vec::new();
    for row in result {
        let row = row.expect("Failed to get row");
        let id: i64 = row.get(0).unwrap();
        ids.push(id);
    }

    assert_eq!(ids, vec![4, 5, 6], "Expected ids [4, 5, 6]");
}

// =============================================================================
// IN List Index Optimization Tests
// =============================================================================

#[test]
fn test_in_list_with_pk() {
    let db = Database::open("memory://in_list_pk").expect("Failed to create database");
    setup_indexed_table(&db);

    let result = db
        .query(
            "SELECT id, name FROM products WHERE id IN (1, 3, 5, 7, 9)",
            (),
        )
        .expect("Failed to query");

    let mut ids = Vec::new();
    for row in result {
        let row = row.expect("Failed to get row");
        let id: i64 = row.get(0).unwrap();
        ids.push(id);
    }
    ids.sort();

    assert_eq!(ids, vec![1, 3, 5, 7, 9], "Expected odd ids");
}

#[test]
fn test_in_list_with_index() {
    let db = Database::open("memory://in_list_index").expect("Failed to create database");
    setup_indexed_table(&db);

    let result = db
        .query(
            "SELECT id, category FROM products WHERE category IN ('Electronics', 'Books')",
            (),
        )
        .expect("Failed to query");

    let mut count = 0;
    for row in result {
        let row = row.expect("Failed to get row");
        let category: String = row.get(1).unwrap();
        assert!(
            category == "Electronics" || category == "Books",
            "Unexpected category: {}",
            category
        );
        count += 1;
    }

    assert_eq!(count, 7, "Expected 7 rows (4 Electronics + 3 Books)");
}

#[test]
fn test_in_list_with_limit() {
    let db = Database::open("memory://in_list_limit").expect("Failed to create database");
    setup_indexed_table(&db);

    let result = db
        .query(
            "SELECT id FROM products WHERE id IN (1, 2, 3, 4, 5) LIMIT 3",
            (),
        )
        .expect("Failed to query");

    let mut count = 0;
    for _ in result {
        count += 1;
    }

    assert_eq!(count, 3, "Expected 3 rows due to LIMIT");
}

#[test]
fn test_in_list_with_offset() {
    let db = Database::open("memory://in_list_offset").expect("Failed to create database");
    setup_indexed_table(&db);

    let result = db
        .query(
            "SELECT id FROM products WHERE id IN (1, 2, 3, 4, 5) LIMIT 2 OFFSET 2",
            (),
        )
        .expect("Failed to query");

    let mut count = 0;
    for _ in result {
        count += 1;
    }

    assert_eq!(count, 2, "Expected 2 rows due to OFFSET 2 LIMIT 2");
}

#[test]
fn test_in_list_empty() {
    let db = Database::open("memory://in_list_empty").expect("Failed to create database");
    setup_indexed_table(&db);

    // Empty IN list - should return no rows
    let result = db
        .query("SELECT id FROM products WHERE id IN (100, 200, 300)", ())
        .expect("Failed to query");

    let mut count = 0;
    for _ in result {
        count += 1;
    }

    assert_eq!(count, 0, "Expected 0 rows for non-existent ids");
}

#[test]
fn test_in_list_with_additional_predicate() {
    let db = Database::open("memory://in_list_additional_pred").expect("Failed to create database");
    setup_indexed_table(&db);

    // IN list with additional WHERE condition
    let result = db
        .query(
            "SELECT id, price FROM products WHERE id IN (1, 2, 3, 4, 5) AND price > 200",
            (),
        )
        .expect("Failed to query");

    let mut ids = Vec::new();
    for row in result {
        let row = row.expect("Failed to get row");
        let id: i64 = row.get(0).unwrap();
        let price: f64 = row.get(1).unwrap();
        assert!(price > 200.0, "Expected price > 200, got {}", price);
        ids.push(id);
    }
    ids.sort();

    // Products with id in (1,2,3,4,5) and price > 200:
    // id=1 (Laptop, 999.99), id=2 (Phone, 599.99), id=3 (Tablet, 399.99), id=5 (Desk, 299.99)
    // All have price > 200
    assert!(!ids.is_empty(), "Expected some ids with price > 200");
}

// =============================================================================
// IN Subquery Index Optimization Tests
// =============================================================================

#[test]
fn test_in_subquery_with_pk() {
    let db = Database::open("memory://in_subquery_pk").expect("Failed to create database");
    setup_indexed_table(&db);

    // Create another table for subquery
    db.execute(
        "CREATE TABLE featured_ids (product_id INTEGER PRIMARY KEY)",
        (),
    )
    .expect("Failed to create table");

    db.execute("INSERT INTO featured_ids VALUES (1)", ())
        .unwrap();
    db.execute("INSERT INTO featured_ids VALUES (3)", ())
        .unwrap();
    db.execute("INSERT INTO featured_ids VALUES (5)", ())
        .unwrap();

    let result = db
        .query(
            "SELECT id, name FROM products WHERE id IN (SELECT product_id FROM featured_ids)",
            (),
        )
        .expect("Failed to query");

    let mut ids = Vec::new();
    for row in result {
        let row = row.expect("Failed to get row");
        let id: i64 = row.get(0).unwrap();
        ids.push(id);
    }
    ids.sort();

    assert_eq!(ids, vec![1, 3, 5], "Expected featured product ids");
}

#[test]
fn test_not_in_subquery_with_pk() {
    let db = Database::open("memory://not_in_subquery_pk").expect("Failed to create database");
    setup_indexed_table(&db);

    // Create table with ids to exclude
    db.execute(
        "CREATE TABLE excluded_ids (product_id INTEGER PRIMARY KEY)",
        (),
    )
    .expect("Failed to create table");

    db.execute("INSERT INTO excluded_ids VALUES (1)", ())
        .unwrap();
    db.execute("INSERT INTO excluded_ids VALUES (2)", ())
        .unwrap();
    db.execute("INSERT INTO excluded_ids VALUES (3)", ())
        .unwrap();

    let result = db
        .query(
            "SELECT id FROM products WHERE id NOT IN (SELECT product_id FROM excluded_ids) ORDER BY id",
            (),
        )
        .expect("Failed to query");

    let mut ids = Vec::new();
    for row in result {
        let row = row.expect("Failed to get row");
        let id: i64 = row.get(0).unwrap();
        ids.push(id);
    }

    assert_eq!(ids, vec![4, 5, 6, 7, 8, 9, 10], "Expected non-excluded ids");
}

#[test]
fn test_in_subquery_empty_result() {
    let db = Database::open("memory://in_subquery_empty").expect("Failed to create database");
    setup_indexed_table(&db);

    // Create empty table
    db.execute(
        "CREATE TABLE empty_ids (product_id INTEGER PRIMARY KEY)",
        (),
    )
    .expect("Failed to create table");

    let result = db
        .query(
            "SELECT id FROM products WHERE id IN (SELECT product_id FROM empty_ids)",
            (),
        )
        .expect("Failed to query");

    let mut count = 0;
    for _ in result {
        count += 1;
    }

    assert_eq!(count, 0, "Expected 0 rows for empty subquery");
}

// =============================================================================
// ORDER BY Index Optimization Tests
// =============================================================================

#[test]
fn test_order_by_indexed_column_asc_limit() {
    let db = Database::open("memory://order_by_asc").expect("Failed to create database");
    setup_indexed_table(&db);

    let result = db
        .query("SELECT id, price FROM products ORDER BY price LIMIT 3", ())
        .expect("Failed to query");

    let mut prices = Vec::new();
    for row in result {
        let row = row.expect("Failed to get row");
        let price: f64 = row.get(1).unwrap();
        prices.push(price);
    }

    assert_eq!(prices.len(), 3, "Expected 3 rows");
    // Verify sorted ascending
    assert!(
        prices[0] <= prices[1] && prices[1] <= prices[2],
        "Expected ascending order"
    );
}

#[test]
fn test_order_by_indexed_column_desc_limit() {
    let db = Database::open("memory://order_by_desc").expect("Failed to create database");
    setup_indexed_table(&db);

    let result = db
        .query(
            "SELECT id, price FROM products ORDER BY price DESC LIMIT 3",
            (),
        )
        .expect("Failed to query");

    let mut prices = Vec::new();
    for row in result {
        let row = row.expect("Failed to get row");
        let price: f64 = row.get(1).unwrap();
        prices.push(price);
    }

    assert_eq!(prices.len(), 3, "Expected 3 rows");
    // Verify sorted descending
    assert!(
        prices[0] >= prices[1] && prices[1] >= prices[2],
        "Expected descending order"
    );
}

#[test]
fn test_order_by_pk_with_offset() {
    let db = Database::open("memory://order_by_offset").expect("Failed to create database");
    setup_indexed_table(&db);

    let result = db
        .query("SELECT id FROM products ORDER BY id LIMIT 3 OFFSET 5", ())
        .expect("Failed to query");

    let mut ids = Vec::new();
    for row in result {
        let row = row.expect("Failed to get row");
        let id: i64 = row.get(0).unwrap();
        ids.push(id);
    }

    assert_eq!(ids, vec![6, 7, 8], "Expected ids [6, 7, 8] after OFFSET 5");
}

// =============================================================================
// Window Function Safety Tests
// =============================================================================

#[test]
fn test_window_row_number_with_limit() {
    let db = Database::open("memory://window_row_number").expect("Failed to create database");
    setup_indexed_table(&db);

    let result = db
        .query(
            "SELECT id, name, ROW_NUMBER() OVER (ORDER BY price) as rn FROM products LIMIT 5",
            (),
        )
        .expect("Failed to query");

    let mut count = 0;
    for row in result {
        let row = row.expect("Failed to get row");
        let rn: i64 = row.get(2).unwrap();
        count += 1;
        assert!((1..=5).contains(&rn), "Expected row number 1-5, got {}", rn);
    }

    assert_eq!(count, 5, "Expected 5 rows");
}

#[test]
fn test_window_rank_basic() {
    // Use a fresh, minimal table for RANK test
    let db = Database::open("memory://rank_simple").expect("Failed to create database");

    db.execute(
        "CREATE TABLE items (id INTEGER PRIMARY KEY, val INTEGER)",
        (),
    )
    .expect("Failed to create table");
    db.execute("INSERT INTO items VALUES (1, 10)", ()).unwrap();
    db.execute("INSERT INTO items VALUES (2, 20)", ()).unwrap();
    db.execute("INSERT INTO items VALUES (3, 20)", ()).unwrap();
    db.execute("INSERT INTO items VALUES (4, 30)", ()).unwrap();

    let result = db
        .query(
            "SELECT id, val, RANK() OVER (ORDER BY val) as rnk FROM items",
            (),
        )
        .expect("Failed to query");

    let mut count = 0;
    for row in result {
        let row = row.expect("Failed to get row");
        let rnk: i64 = row.get(2).unwrap();
        assert!(rnk >= 1, "Expected rank >= 1, got {}", rnk);
        count += 1;
    }

    assert_eq!(count, 4, "Expected 4 rows");
}

#[test]
fn test_window_dense_rank_basic() {
    // Use a fresh, minimal table for DENSE_RANK test
    let db = Database::open("memory://dense_rank_simple").expect("Failed to create database");

    db.execute(
        "CREATE TABLE items (id INTEGER PRIMARY KEY, val INTEGER)",
        (),
    )
    .expect("Failed to create table");
    db.execute("INSERT INTO items VALUES (1, 10)", ()).unwrap();
    db.execute("INSERT INTO items VALUES (2, 20)", ()).unwrap();
    db.execute("INSERT INTO items VALUES (3, 20)", ()).unwrap();
    db.execute("INSERT INTO items VALUES (4, 30)", ()).unwrap();

    let result = db
        .query(
            "SELECT id, val, DENSE_RANK() OVER (ORDER BY val) as drnk FROM items",
            (),
        )
        .expect("Failed to query");

    let mut count = 0;
    for row in result {
        let row = row.expect("Failed to get row");
        let drnk: i64 = row.get(2).unwrap();
        assert!(drnk >= 1, "Expected dense_rank >= 1, got {}", drnk);
        count += 1;
    }

    assert_eq!(count, 4, "Expected 4 rows");
}

// =============================================================================
// Equality Condition Detection Tests (for hash join eligibility)
// =============================================================================

#[test]
fn test_join_with_equality() {
    let db = Database::open("memory://join_equality").expect("Failed to create database");
    setup_indexed_table(&db);

    // Create orders table
    db.execute(
        "CREATE TABLE orders (id INTEGER PRIMARY KEY, product_id INTEGER, quantity INTEGER)",
        (),
    )
    .expect("Failed to create table");

    db.execute("INSERT INTO orders VALUES (1, 1, 2)", ())
        .unwrap();
    db.execute("INSERT INTO orders VALUES (2, 2, 1)", ())
        .unwrap();
    db.execute("INSERT INTO orders VALUES (3, 1, 3)", ())
        .unwrap();

    // Join with equality condition
    let result = db
        .query(
            "SELECT p.name, o.quantity
             FROM products p
             INNER JOIN orders o ON p.id = o.product_id",
            (),
        )
        .expect("Failed to query");

    let mut count = 0;
    for _ in result {
        count += 1;
    }

    assert_eq!(count, 3, "Expected 3 joined rows");
}

// =============================================================================
// Cardinality Estimation Tests
// =============================================================================

#[test]
fn test_explain_shows_plan() {
    let db = Database::open("memory://explain_estimates").expect("Failed to create database");
    setup_indexed_table(&db);

    // Run ANALYZE first
    db.execute("ANALYZE products", ())
        .expect("Failed to ANALYZE");

    let result = db
        .query("EXPLAIN SELECT * FROM products WHERE price > 100", ())
        .expect("Failed to EXPLAIN");

    let mut lines = Vec::new();
    for row in result {
        let row = row.expect("Failed to get row");
        let plan: String = row.get(0).unwrap();
        lines.push(plan);
    }

    // EXPLAIN should return something about the query plan
    assert!(!lines.is_empty(), "Expected EXPLAIN to return plan lines");
}