Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Incorrect Comparison Logic for Strings #850

Open
@apavlo

Description

@apavlo

The logic for our VarlenType comparison types are incorrect.We use memcmp, which causes it to incorrectly say that one string is less than another if it is shorter:

https://github.com/cmu-db/peloton/blob/master/src/include/type/type_util.h#L42

This is because we need to do a comparison of strings that are not null terminated.

I'm not sure what the SQL standard says but I suspect that Postgres is doing it correctly. Here are some other examples of string comparisons in other systems. Note that sqlite doesn't follow the standard either.

Postgres

pavlo=# SELECT 'aaaaa' < 'Z';
 ?column? 
----------
 t
(1 row)

MySQL

mysql> SELECT 'aaaaa' < 'Z';
+---------------+
| 'aaaaa' < 'Z' |
+---------------+
|             1 |
+---------------+

SQLite

sqlite> SELECT 'aaaaa' < 'Z';
'aaaaa' < 'Z'
-------------
0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions