Open docwilco opened 3 months ago
0.7.4 outputs:
no GROUP BY: alloc::string::String/i64
GROUP BY only: alloc::string::String
GROUP BY + MIN(): core::option::Option<alloc::string::String>/i32
GROUP BY + MAX(): core::option::Option<alloc::string::String>/i32
GROUP BY + SUM(): alloc::string::String/i32
GROUP BY + COUNT(): alloc::string::String/i32
GROUP BY + AVG(): alloc::string::String/f64
GROUP BY + TOTAL(): alloc::string::String/f64
With main
branch (0449ac5) I get:
no GROUP BY: alloc::string::String/i64
GROUP BY only: alloc::string::String
GROUP BY + MIN(): core::option::Option<alloc::string::String>/i64
GROUP BY + MAX(): core::option::Option<alloc::string::String>/i64
GROUP BY + SUM(): alloc::string::String/i64
GROUP BY + COUNT(): alloc::string::String/i64
GROUP BY + AVG(): alloc::string::String/f64
GROUP BY + TOTAL(): alloc::string::String/f64
So things are fixed except for the String
becoming Option<String>
for MIN()
and MAX()
.
Thanks for the reproducer.
I tweaked your reproducer so that I could dump a trace of the potential opcode execution paths, then commented out the execution paths that were irrelevant, to see what is going on. https://gist.github.com/tyrelr/daf8e0ee29a2bcd978d1d95da199b5f7
At a glance I would guess that the issue is due to min/max not being implemented by the AggFinal command (as that seems to be where the null value comes from in the graph). But I haven't dug in, so that's just a guess.
The code to change would be in sqlx-sqlite/src/connection/explain.rs, if you want to give it a try.
Bug Description
When using
GROUP BY
on aNON NULL
column, said column becomes anOption<T>
in combination with theMIN()
andMAX()
aggregate functions. AlsoMIN()
,MAX()
,SUM()
, andCOUNT()
geti32
as type, noti64
. As the testcase shows,AVG()
andTOTAL()
seem to behave correctly.Minimal Reproduction
https://gist.github.com/docwilco/b5ea0972a21714a4d0f2c3e824b45c1e
Info
sqlite
,runtime-tokio
rustc --version
:rustc 1.77.2 (25ef9e3d8 2024-04-09)
Also tried with:
rustc 1.78.0 (9b00956e5 2024-04-29)