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

Wrong ordering with views, distinct, left join and order by [CORE1089] #1510

Closed
firebird-issue-importer opened this issue Jan 16, 2007 · 16 comments
Closed

Comments

@firebird-issue-importer

Submitted by: Nando Dessena (nando.dessena)

Is duplicated by CORE2863
Is duplicated by CORE2870
Relate to CORE2871
Is related to QA247
Is duplicated by CORE1974

Votes: 2

Selecting from a view that uses distinct and left join returns records in the wrong order if the order by clause doesn't include columns from the right (non-mandatory) table. Test case:

CREATE TABLE FAT
(
IDXXFAT VARCHAR(26) NOT NULL,
PROGFAT INTEGER,
IDXXCCB VARCHAR(20),
NDONFAT INTEGER,
CONSTRAINT PK$_FAT PRIMARY KEY (IDXXFAT)
);

COMMIT;

INSERT INTO FAT (IDXXFAT,PROGFAT,IDXXCCB,NDONFAT) values
('2007.1',1,'Y',1002);
INSERT INTO FAT (IDXXFAT,PROGFAT,IDXXCCB,NDONFAT) values
('2007.2',2,'X',1001);

COMMIT;

CREATE TABLE SCA
(
IDXXSCA VARCHAR(16) NOT NULL,
PROGSCA INTEGER,
IDXXFAT VARCHAR(26),
CONSTRAINT PK$_SCA PRIMARY KEY (IDXXSCA)
);

COMMIT;

INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.4',4,'2007.1');
INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.3',3,'2007.1');
INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.2',2,'2007.2');
INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.1',1,'2007.2');

COMMIT;

CREATE VIEW VW$_SCA (
IDXXSCA,
PROGSCA,
IDXXFAT,
IDXXCCB,
NDONFAT
) AS
SELECT DISTINCT
SCA.IDXXSCA,
SCA.PROGSCA,
SCA.IDXXFAT,
FAT.IDXXCCB,
FAT.NDONFAT
FROM
SCA LEFT JOIN FAT ON SCA.IDXXFAT=FAT.IDXXFAT;

COMMIT;

SQL> select * from vw$_sca order by 2 desc;

IDXXSCA PROGSCA IDXXFAT [truncated]
================ ============ ==============
2007.1 1 2007.2
2007.2 2 2007.2
2007.3 3 2007.1
2007.4 4 2007.1

Wrong order.

SQL> select * from vw$_sca order by progsca desc, idxxccb desc;

IDXXSCA PROGSCA IDXXFAT IDXXCCB [truncated]
================ ============ =========== =======
2007.4 4 2007.1 Y
2007.3 3 2007.1 Y
2007.2 2 2007.2 X
2007.1 1 2007.2 X

Correct order.

Commits: 3aaa3d1 98e83cd 99ccecb f815326

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 16, 2007

Modified by: Nando Dessena (nando.dessena)

description: Selecting from a view that uses distinct and left join returna records in the wrong order if the order by clause doesn't include columns from the right (non-mandatory) table. Test case:

CREATE TABLE FAT
(
IDXXFAT VARCHAR(26) NOT NULL,
PROGFAT INTEGER,
IDXXCCB VARCHAR(20),
NDONFAT INTEGER,
CONSTRAINT PK$_FAT PRIMARY KEY (IDXXFAT)
);

COMMIT;

INSERT INTO FAT (IDXXFAT,PROGFAT,IDXXCCB,NDONFAT) values
('2007.1',1,'Y',1002);
INSERT INTO FAT (IDXXFAT,PROGFAT,IDXXCCB,NDONFAT) values
('2007.2',2,'X',1001);

COMMIT;

CREATE TABLE SCA
(
IDXXSCA VARCHAR(16) NOT NULL,
PROGSCA INTEGER,
IDXXFAT VARCHAR(26),
CONSTRAINT PK$_SCA PRIMARY KEY (IDXXSCA)
);

COMMIT;

INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.4',4,'2007.1');
INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.3',3,'2007.1');
INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.2',2,'2007.2');
INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.1',1,'2007.2');

COMMIT;

CREATE VIEW VW$_SCA (
IDXXSCA,
PROGSCA,
IDXXFAT,
IDXXCCB,
NDONFAT
) AS
SELECT DISTINCT
SCA.IDXXSCA,
SCA.PROGSCA,
SCA.IDXXFAT,
FAT.IDXXCCB,
FAT.NDONFAT
FROM
SCA LEFT JOIN FAT ON SCA.IDXXFAT=FAT.IDXXFAT;

COMMIT;

SQL> select * from vw$_sca order by 2 desc;

IDXXSCA PROGSCA IDXXFAT [truncated]
================ ============ ==============
2007.1 1 2007.2
2007.2 2 2007.2
2007.3 3 2007.1
2007.4 4 2007.1

Wrong ordering.

SQL> select * from vw$_sca order by progsca desc, idxxccb desc;

IDXXSCA PROGSCA IDXXFAT IDXXCCB [truncated]
================ ============ =========== =======
2007.4 4 2007.1 Y
2007.3 3 2007.1 Y
2007.2 2 2007.2 X
2007.1 1 2007.2 X

Correct ordering.

=>

Selecting from a view that uses distinct and left join returns records in the wrong order if the order by clause doesn't include columns from the right (non-mandatory) table. Test case:

CREATE TABLE FAT
(
IDXXFAT VARCHAR(26) NOT NULL,
PROGFAT INTEGER,
IDXXCCB VARCHAR(20),
NDONFAT INTEGER,
CONSTRAINT PK$_FAT PRIMARY KEY (IDXXFAT)
);

COMMIT;

INSERT INTO FAT (IDXXFAT,PROGFAT,IDXXCCB,NDONFAT) values
('2007.1',1,'Y',1002);
INSERT INTO FAT (IDXXFAT,PROGFAT,IDXXCCB,NDONFAT) values
('2007.2',2,'X',1001);

COMMIT;

CREATE TABLE SCA
(
IDXXSCA VARCHAR(16) NOT NULL,
PROGSCA INTEGER,
IDXXFAT VARCHAR(26),
CONSTRAINT PK$_SCA PRIMARY KEY (IDXXSCA)
);

COMMIT;

INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.4',4,'2007.1');
INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.3',3,'2007.1');
INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.2',2,'2007.2');
INSERT INTO SCA (IDXXSCA,PROGSCA,IDXXFAT) values ('2007.1',1,'2007.2');

COMMIT;

CREATE VIEW VW$_SCA (
IDXXSCA,
PROGSCA,
IDXXFAT,
IDXXCCB,
NDONFAT
) AS
SELECT DISTINCT
SCA.IDXXSCA,
SCA.PROGSCA,
SCA.IDXXFAT,
FAT.IDXXCCB,
FAT.NDONFAT
FROM
SCA LEFT JOIN FAT ON SCA.IDXXFAT=FAT.IDXXFAT;

COMMIT;

SQL> select * from vw$_sca order by 2 desc;

IDXXSCA PROGSCA IDXXFAT [truncated]
================ ============ ==============
2007.1 1 2007.2
2007.2 2 2007.2
2007.3 3 2007.1
2007.4 4 2007.1

Wrong order.

SQL> select * from vw$_sca order by progsca desc, idxxccb desc;

IDXXSCA PROGSCA IDXXFAT IDXXCCB [truncated]
================ ============ =========== =======
2007.4 4 2007.1 Y
2007.3 3 2007.1 Y
2007.2 2 2007.2 X
2007.1 1 2007.2 X

Correct order.

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Nov 13, 2007

Modified by: @dyemanov

assignee: Dmitry Yemanov [ dimitr ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 28, 2008

Modified by: @pcisar

Workflow: jira [ 11502 ] => Firebird [ 15489 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 14, 2010

Modified by: @dyemanov

Link: This issue is duplicated by CORE2863 [ CORE2863 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 16, 2010

Modified by: @dyemanov

Link: This issue is duplicated by CORE2870 [ CORE2870 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 16, 2010

Modified by: @dyemanov

status: Open [ 1 ] => In Progress [ 3 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 16, 2010

Modified by: @dyemanov

Version: 2.5 RC2 [ 10372 ]

Version: 2.5 RC1 [ 10362 ]

Version: 3.0 Initial [ 10301 ]

Version: 2.1.3 [ 10302 ]

Version: 2.5 Beta 2 [ 10300 ]

Version: 2.5 Beta 1 [ 10251 ]

Version: 2.1.2 [ 10270 ]

Version: 2.0.5 [ 10222 ]

Version: 2.1.1 [ 10223 ]

Version: 2.5 Alpha 1 [ 10224 ]

Version: 2.0.4 [ 10211 ]

Version: 2.1.0 [ 10041 ]

Version: 2.0.3 [ 10200 ]

Version: 2.0.2 [ 10130 ]

Version: 2.0.1 [ 10090 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 16, 2010

Modified by: @dyemanov

Link: This issue relate to CORE2871 [ CORE2871 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 16, 2010

Modified by: @dyemanov

status: In Progress [ 3 ] => Open [ 1 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 16, 2010

Modified by: @dyemanov

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 2.0.6 [ 10303 ]

Fix Version: 2.5 RC3 [ 10381 ]

Fix Version: 2.1.4 [ 10361 ]

Fix Version: 3.0 Alpha 1 [ 10331 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 23, 2011

Modified by: @pcisar

Link: This issue is related to QA247 [ QA247 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Mar 21, 2011

Commented by: @pmakowski

QA test made

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Mar 21, 2011

Modified by: @pmakowski

status: Resolved [ 5 ] => Closed [ 6 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Mar 15, 2012

Modified by: @dyemanov

Link: This issue is duplicated by CORE1974 [ CORE1974 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 19, 2016

Modified by: @pavel-zotov

QA Status: No test

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 4, 2016

Modified by: @pavel-zotov

status: Closed [ 6 ] => Closed [ 6 ]

QA Status: No test => Done successfully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment