Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count distinct is not supported #741

Open
Tracked by #738
psvri opened this issue Jan 19, 2025 · 1 comment · May be fixed by #1139
Open
Tracked by #738

Count distinct is not supported #741

psvri opened this issue Jan 19, 2025 · 1 comment · May be fixed by #1139
Labels
bug Something isn't working compatibility help wanted Extra attention is needed

Comments

@psvri
Copy link
Contributor

psvri commented Jan 19, 2025

LImbo returns the wrong results for count distinct as shown below

sqlite3

sqlite> create table temp2 (t1 text);
sqlite> insert into temp2 values ('1'),('1'),('2');
sqlite> select count(*) from temp2;
3
sqlite> select count(distinct t1) from temp2;
2

limbo

limbo> create table temp2 (t1 text);
limbo> insert into temp2 values ('1'),('1'),('2');
limbo> select count(*) from temp2;
3
limbo> select count(distinct t1) from temp2;
3
@psvri psvri mentioned this issue Jan 19, 2025
4 tasks
@krishvishal
Copy link
Contributor

SQLite query plan

sqlite> EXPLAIN select count(distinct t1) from temp2; 
addr  opcode         p1    p2    p3    p4             p5  comment        
----  -------------  ----  ----  ----  -------------  --  -------------  
0     Init           0     15    0                    0                  
1     Null           0     1     2                    0                  
2     OpenEphemeral  1     0     0     k(1,B)         0                  
3     OpenRead       0     2     0     1              0                  
4     Rewind         0     11    0                    0                  
5       Column         0     0     3                    0
6       Found          1     10    3     1              0
7       MakeRecord     3     1     4                    0
8       IdxInsert      1     4     3     1              16
9       AggStep        0     3     1     count(1)       1
10    Next           0     5     0                    1                  
11    AggFinal       1     1     0     count(1)       0                  
12    Copy           1     5     0                    0                  
13    ResultRow      5     1     0                    0                  
14    Halt           0     0     0                    0                  
15    Transaction    0     0     1     0              1                  
16    Goto           0     1     0                    0                  

vs

limbo query plan

limbo> EXPLAIN select count(distinct t1) from temp2;
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     13    0                    0   Start at 13
1     OpenReadAsync      0     2     0                    0   table=temp2, root=2
2     OpenReadAwait      0     0     0                    0
3     RewindAsync        0     0     0                    0
4     RewindAwait        0     9     0                    0   Rewind table temp2
5       Column           0     0     3                    0   r[3]=temp2.t1
6       AggStep          0     3     2     count          0   accum=r[2] step(r[3])
7     NextAsync          0     0     0                    0
8     NextAwait          0     5     0                    0
9     AggFinal           0     2     0     count          0   accum=r[2]
10    Copy               2     1     0                    0   r[1]=r[2]
11    ResultRow          1     1     0                    0   output=r[1]
12    Halt               0     0     0                    0
13    Transaction        0     0     0                    0
14    Goto               0     1     0                    0

@penberg penberg added bug Something isn't working help wanted Extra attention is needed compatibility labels Jan 19, 2025
@penberg penberg added Stale and removed Stale labels Feb 19, 2025
lgualtieri75 added a commit to lgualtieri75/limbo that referenced this issue Mar 1, 2025
@diegoreis42 diegoreis42 linked a pull request Mar 19, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compatibility help wanted Extra attention is needed
Projects
None yet
3 participants