Skip to content
New issue

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

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

Already on GitHub? # to your account

Wrong select result in case of special sort character. #7140

Closed
LMasak opened this issue Mar 2, 2022 · 4 comments
Closed

Wrong select result in case of special sort character. #7140

LMasak opened this issue Mar 2, 2022 · 4 comments

Comments

@LMasak
Copy link

LMasak commented Mar 2, 2022

Originally discovered with Polish collation but same problem for Czech. Tested with FB3, FB4 and ICU4.2, ICU 5.2, ICU 6.3

To get wrong result you must meet all of the following conditions:

  • test column that has a sort assigned with a special sort for some characters
  • use the less "<" operator
  • use a character with a special order, eg in Czech it is an "c" alphabetical order a, b, c, č, d
  • combine it with statement "or value is null"

create collation test_cz for UTF8 FROM UNICODE CASE INSENSITIVE ACCENT SENSITIVE 'LOCALE=cs_CZ';
CREATE TABLE TBL_TEST
( C1 VARCHAR(50) collate test_cz
);
CREATE INDEX IDX_c1 ON TBL_TEST (C1);
CREATE DESCENDING INDEX IDX_c1_d ON TBL_TEST (C1);

INSERT INTO TBL_TEST (C1) VALUES ('aaa');
INSERT INTO TBL_TEST (C1) VALUES ('bbb');
INSERT INTO TBL_TEST (C1) VALUES ('ccc');
INSERT INTO TBL_TEST (C1) VALUES ('ddd');
INSERT INTO TBL_TEST (C1) VALUES (NULL);

select * from TBL_TEST where c1 < 'b' or c1 is null order by c1 desc
result:
1 aaa
2 [null]

select * from TBL_TEST where c1 < 'c' or c1 is null order by c1 desc
result:
1 [null]

select * from TBL_TEST where c1 < 'd' or c1 is null order by c1 desc
result:
1 ccc
2 bbb
3 aaa
4 [null]

@asfernandes asfernandes self-assigned this Mar 2, 2022
@asfernandes
Copy link
Member

Fixed in #7131

@asfernandes
Copy link
Member

select * from TBL_TEST where c1 < 'c' or c1 is null order by c1 desc result: 1 [null]

Result should be this, correct?

bbb                                                
aaa                                                
<null>                                             

@LMasak
Copy link
Author

LMasak commented Mar 2, 2022

exactly thank you

asfernandes added a commit that referenced this issue Mar 16, 2022
- #7093 - Improve indexed lookup speed of strings when the last
keys characters are part of collated contractions.

- #7094 - Incorrect indexed lookup of strings when the last keys
characters are part of collated contractions and there is
multi-segment insensitive descending index.

- #7140 - Wrong select result in case of special sort character.
asfernandes added a commit that referenced this issue Mar 17, 2022
- #7093 - Improve indexed lookup speed of strings when the last
keys characters are part of collated contractions.

- #7094 - Incorrect indexed lookup of strings when the last keys
characters are part of collated contractions and there is
multi-segment insensitive descending index.

- #7140 - Wrong select result in case of special sort character.
asfernandes added a commit that referenced this issue Mar 17, 2022
- #7093 - Improve indexed lookup speed of strings when the last
keys characters are part of collated contractions.

- #7094 - Incorrect indexed lookup of strings when the last keys
characters are part of collated contractions and there is
multi-segment insensitive descending index.

- #7140 - Wrong select result in case of special sort character.
@pavel-zotov
Copy link

=== QA notes ===
Test fails on 3.0.12 with 'invalid collation attribute', thus min_version was set to 4.0.2.

# for free to join this conversation on GitHub. Already have an account? # to comment