@@ -1218,18 +1218,18 @@ pub mod tests_utils {
1218
1218
use crate :: printer:: { Explain , ExplainOptions } ;
1219
1219
use crate :: PhysicalCtx ;
1220
1220
use expect_test:: Expect ;
1221
- use spacetimedb_expr:: check:: { compile_sql_sub, SchemaView } ;
1221
+ use spacetimedb_expr:: check:: { compile_sql_sub, SchemaView , TypingResult } ;
1222
1222
use spacetimedb_expr:: statement:: compile_sql_stmt_with_ctx;
1223
1223
use spacetimedb_lib:: identity:: AuthCtx ;
1224
1224
1225
- fn sub < ' a > ( db : & ' a impl SchemaView , auth : & AuthCtx , sql : & ' a str ) -> PhysicalCtx < ' a > {
1226
- let plan = compile_sql_sub ( sql, db, auth, true ) . unwrap ( ) ;
1227
- compile ( plan)
1225
+ fn sub < ' a > ( db : & ' a impl SchemaView , auth : & AuthCtx , sql : & ' a str ) -> TypingResult < PhysicalCtx < ' a > > {
1226
+ let plan = compile_sql_sub ( sql, db, auth, true ) ? ;
1227
+ Ok ( compile ( plan) )
1228
1228
}
1229
1229
1230
- fn query < ' a > ( db : & ' a impl SchemaView , auth : & AuthCtx , sql : & ' a str ) -> PhysicalCtx < ' a > {
1231
- let plan = compile_sql_stmt_with_ctx ( sql, db, auth, true ) . unwrap ( ) ;
1232
- compile ( plan)
1230
+ fn query < ' a > ( db : & ' a impl SchemaView , auth : & AuthCtx , sql : & ' a str ) -> TypingResult < PhysicalCtx < ' a > > {
1231
+ let plan = compile_sql_stmt_with_ctx ( sql, db, auth, true ) ? ;
1232
+ Ok ( compile ( plan) )
1233
1233
}
1234
1234
1235
1235
fn check ( plan : PhysicalCtx , options : ExplainOptions , expect : Expect ) {
@@ -1242,14 +1242,28 @@ pub mod tests_utils {
1242
1242
expect. assert_eq ( & explain. to_string ( ) ) ;
1243
1243
}
1244
1244
1245
- pub fn check_sub ( db : & impl SchemaView , options : ExplainOptions , auth : & AuthCtx , sql : & str , expect : Expect ) {
1246
- let plan = sub ( db, auth, sql) ;
1245
+ pub fn check_sub (
1246
+ db : & impl SchemaView ,
1247
+ options : ExplainOptions ,
1248
+ auth : & AuthCtx ,
1249
+ sql : & str ,
1250
+ expect : Expect ,
1251
+ ) -> TypingResult < ( ) > {
1252
+ let plan = sub ( db, auth, sql) ?;
1247
1253
check ( plan, options, expect) ;
1254
+ Ok ( ( ) )
1248
1255
}
1249
1256
1250
- pub fn check_query ( db : & impl SchemaView , options : ExplainOptions , auth : & AuthCtx , sql : & str , expect : Expect ) {
1251
- let plan = query ( db, auth, sql) ;
1257
+ pub fn check_query (
1258
+ db : & impl SchemaView ,
1259
+ options : ExplainOptions ,
1260
+ auth : & AuthCtx ,
1261
+ sql : & str ,
1262
+ expect : Expect ,
1263
+ ) -> TypingResult < ( ) > {
1264
+ let plan = query ( db, auth, sql) ?;
1252
1265
check ( plan, options, expect) ;
1266
+ Ok ( ( ) )
1253
1267
}
1254
1268
}
1255
1269
@@ -1367,11 +1381,11 @@ mod tests {
1367
1381
}
1368
1382
1369
1383
fn check_sub ( db : & SchemaViewer , sql : & str , expect : Expect ) {
1370
- tests_utils:: check_sub ( db, db. options , & AuthCtx :: for_testing ( ) , sql, expect) ;
1384
+ tests_utils:: check_sub ( db, db. options , & AuthCtx :: for_testing ( ) , sql, expect) . unwrap ( ) ;
1371
1385
}
1372
1386
1373
1387
fn check_query ( db : & SchemaViewer , sql : & str , expect : Expect ) {
1374
- tests_utils:: check_query ( db, db. options , & AuthCtx :: for_testing ( ) , sql, expect) ;
1388
+ tests_utils:: check_query ( db, db. options , & AuthCtx :: for_testing ( ) , sql, expect) . unwrap ( ) ;
1375
1389
}
1376
1390
1377
1391
fn data ( ) -> SchemaViewer {
@@ -2055,4 +2069,56 @@ Delete on p
2055
2069
-> Filter: (p.id = U64(1))"# ] ] ,
2056
2070
) ;
2057
2071
}
2072
+
2073
+ #[ test]
2074
+ fn count ( ) {
2075
+ let db = data ( ) . with_options ( ExplainOptions :: default ( ) . optimize ( true ) ) ;
2076
+
2077
+ check_query (
2078
+ & db,
2079
+ "SELECT count(*) as n FROM p" ,
2080
+ expect ! [ [ r#"
2081
+ Count
2082
+ Output: n
2083
+ -> Seq Scan on p
2084
+ Output: p.id, p.name"# ] ] ,
2085
+ ) ;
2086
+
2087
+ check_query (
2088
+ & db,
2089
+ "SELECT count(*) as n FROM p WHERE id = 1" ,
2090
+ expect ! [ [ r#"
2091
+ Count
2092
+ Output: n
2093
+ -> Index Scan using Index id 0 Unique(p.id) on p
2094
+ Index Cond: (p.id = U64(1))
2095
+ Output: p.id, p.name"# ] ] ,
2096
+ ) ;
2097
+ }
2098
+
2099
+ #[ test]
2100
+ fn limit ( ) {
2101
+ let db = data ( ) . with_options ( ExplainOptions :: default ( ) . optimize ( true ) ) ;
2102
+
2103
+ check_query (
2104
+ & db,
2105
+ "SELECT * FROM p LIMIT 10" ,
2106
+ expect ! [ [ r#"
2107
+ Limit: 10
2108
+ Output: p.id, p.name
2109
+ -> Seq Scan on p
2110
+ Output: p.id, p.name"# ] ] ,
2111
+ ) ;
2112
+
2113
+ check_query (
2114
+ & db,
2115
+ "SELECT * FROM p WHERE id = 1 LIMIT 10" ,
2116
+ expect ! [ [ r#"
2117
+ Limit: 10
2118
+ Output: p.id, p.name
2119
+ -> Index Scan using Index id 0 Unique(p.id) on p
2120
+ Index Cond: (p.id = U64(1))
2121
+ Output: p.id, p.name"# ] ] ,
2122
+ ) ;
2123
+ }
2058
2124
}
0 commit comments