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

DISTINCT does not work when sorting by additional columns #7202

Closed
nuno-faria opened this issue Nov 22, 2021 · 3 comments
Closed

DISTINCT does not work when sorting by additional columns #7202

nuno-faria opened this issue Nov 22, 2021 · 3 comments
Labels
bug
Milestone

Comments

@nuno-faria
Copy link
Contributor

@nuno-faria nuno-faria commented Nov 22, 2021

Describe the bug
Performing a DISTINCT results in duplicate rows if we sort the table by additional columns than the ones that are projected. This is not critical as the additional columns can be removed from the sort, however it can cause problems with dynamically generated queries (which is how this bug was discovered).

To Reproduce

  • Create a table and populate with some data:

    CREATE TABLE T (t1 int, t2 int);
    INSERT INTO t VALUES (1, 1), (1, 2);
  • DISTINCT with single sort column works as expected:

    SELECT DISTINCT t1
    FROM T 
    ORDER BY t1;
    
    Returns:
    +------+
    | t1   |
    +======+
    |    1 |
    +------+
  • DISTINCT when sorting by both columns returns repeated rows:

    SELECT DISTINCT t1
    FROM T
    ORDER BY t1, t2;
    
    Returns:
    +------+
    | t1   |
    +======+
    |    1 |
    |    1 |
    +------+

Expected behavior
Return just one row with value 1.

Software versions

  • monetdb -v: MonetDB Database Server Toolkit v11.41.11 (Jul2021-SP1).
  • OS: Ubuntu 20.04.3 LTS;
  • Monetdb installed from release packages with apt (packages monetdb5-sql and monetdb-client);
@PedroTadim
Copy link
Contributor

@PedroTadim PedroTadim commented Nov 23, 2021

The order by clause should be computed after the distinct, so the second query should fail to compile. I have a fix in mind.

@PedroTadim PedroTadim added the bug label Nov 23, 2021
@PedroTadim PedroTadim added this to the NEXTFEATURERELEASE milestone Nov 23, 2021
monetdb-team pushed a commit that referenced this issue Nov 23, 2021
…ust match the projection list, otherwise it is not computable
@PedroTadim
Copy link
Contributor

@PedroTadim PedroTadim commented Nov 23, 2021

Because this is a behavior change, I fixed on Jan2022 branch and it will be available on the next feature release.

@nuno-faria
Copy link
Contributor Author

@nuno-faria nuno-faria commented Nov 23, 2021

Thanks, can confirm that the second query does not compile anymore in the Jan22 branch.

@sjoerdmullender sjoerdmullender removed this from the NEXTFEATURERELEASE milestone Jan 24, 2022
@sjoerdmullender sjoerdmullender added this to the Jan2022 milestone Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug
Projects
None yet
Development

No branches or pull requests

3 participants