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

ORDER BY broken when using UNION ALL #3620

Closed
monetdb-team opened this issue Nov 30, 2020 · 0 comments
Closed

ORDER BY broken when using UNION ALL #3620

monetdb-team opened this issue Nov 30, 2020 · 0 comments
Labels
bug Something isn't working major SQL

Comments

@monetdb-team
Copy link

Date: 2014-11-10 15:33:54 +0100
From: Frédéric Jolliton <<frederic.jolliton+monetdb>>
To: SQL devs <>
Version: -- development
CC: @njnes

Last updated: 2014-11-28 10:03:16 +0100

Comment 20435

Date: 2014-11-10 15:33:54 +0100
From: Frédéric Jolliton <<frederic.jolliton+monetdb>>

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0
Build Identifier:

Sadly, we encountered another bug related to UNION ALL. When trying to sort the result of an UNION ALL, the ORDER BY clause doesn't seem to be applied correctly.

Reproducible: Always

Steps to Reproduce:

SELECT val FROM (SELECT 1 AS val UNION ALL SELECT 2) AS foo ORDER BY -val ASC;

Actual Results:

1
2

Expected Results:

2
1

The explain for the query (the "-val" computation appears nowhere):

_4:bat[:oid,:bte] = bat.new(nil:oid, nil:bte)
_7:bat[:oid,:bte] = sql.single(A0:bte)
_8:bat[:oid,:bte] = bat.append(_4:bat[:oid,:bte], _7:bat[:oid,:bte], true:bit)
_9:bat[:oid,:bte] = bat.append(_8:bat[:oid,:bte], A1:bte, true:bit)
_10:bat[:oid,:bte], r1_13:bat[:oid,:oid], r2_13:bat[:oid,:oid] = algebra.subsort(_9:bat[:oid,:bte], false:bit, false:bit)
_14:bat[:oid,:bte] = algebra.leftfetchjoin(r1_13:bat[:oid,:oid], _9:bat[:oid,:bte])
_15:int = sql.resultSet(1:int, 1:int, _14:bat[:oid,:bte])
_17:void = sql.rsColumn(_15:int, ".foo":str, "val":str, "tinyint":str, 8:int, 0:int, _14:bat[:oid,:bte])
_23:streams = io.stdout()
_24:void = sql.exportResult(_23:streams, _15:int)

Wrapping the subselect makes the sort to work:

SELECT val FROM (SELECT * FROM (SELECT 1 AS val UNION ALL SELECT 2) AS foo) AS bar ORDER BY -val ASC;

It produces, as expected:

2
1

$ bin/mserver5 --version
MonetDB 5 server v11.20.0 (64-bit, 64-bit oids, 128-bit integers)

Comment 20439

Date: 2014-11-12 11:00:05 +0100
From: Frédéric Jolliton <<frederic.jolliton+monetdb>>

Version changed to development. (Is that a bug in the tracker? Both my tickets were created with "development" as version, but got stored with Jan2014-SP3..)

Comment 20442

Date: 2014-11-16 18:49:26 +0100
From: MonetDB Mercurial Repository <>

Changeset 504294a644fd made by Niels Nes niels@cwi.nl in the MonetDB repo, refers to this bug.

For complete details, see http//devmonetdborg/hg/MonetDB?cmd=changeset;node=504294a644fd

Changeset description:

fixed bug in order with column expression ie bug #3620

Comment 20443

Date: 2014-11-16 18:50:01 +0100
From: @njnes

Fixed properly handle the extra (order by) expression and extra projection

Comment 20445

Date: 2014-11-18 10:30:34 +0100
From: Frédéric Jolliton <<frederic.jolliton+monetdb>>

Works great. Thanks for the quick fix!

While we found some bugs that could worry us sometimes, we are also impressed by how quickly you fix them. This is greatly appreciated and reassuring.

Comment 20466

Date: 2014-11-28 10:03:16 +0100
From: @sjoerdmullender

Oct2014-SP1 has been released.

@monetdb-team monetdb-team added bug Something isn't working major SQL labels Nov 30, 2020
@sjoerdmullender sjoerdmullender added this to the Ancient Release milestone Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working major SQL
Projects
None yet
Development

No branches or pull requests

2 participants