MaterializeInc / materialize

The Cloud Operational Data Store: use SQL to transform, deliver, and act on fast-changing data.
https://materialize.com
Other
5.72k stars 466 forks source link

Postgres inconsistency: ordering on text (min/max, <, ...) different #22002

Open nrainer-materialize opened 11 months ago

nrainer-materialize commented 11 months ago

Postgres

-- Setup for evaluation strategy 'Postgres evaluation':
DROP TABLE IF EXISTS postgres_evaluation;
CREATE TABLE postgres_evaluation (row_index INT, text_val TEXT);
INSERT INTO postgres_evaluation VALUES (2, 'a'::TEXT);
INSERT INTO postgres_evaluation VALUES (5, ' mAA m
     '::TEXT);
INSERT INTO postgres_evaluation VALUES (14, 'xAAx'::TEXT);
-- Query using evaluation strategy 'Postgres evaluation':
SELECT
  min(text_val)
FROM
  postgres_evaluation
WHERE (row_index IN (2, 5, 14));

produces

 min 
-----
 a

mz

DROP TABLE IF EXISTS dataflow_rendering;
CREATE TABLE dataflow_rendering (row_index INT, text_val TEXT);
INSERT INTO dataflow_rendering VALUES (2, 'a'::TEXT);
INSERT INTO dataflow_rendering VALUES (5, ' mAA m
     '::TEXT);
INSERT INTO dataflow_rendering VALUES (14, 'xAAx'::TEXT);
-- Query using evaluation strategy 'Dataflow rendering':
SELECT
  min(text_val)
FROM
  dataflow_rendering
WHERE (row_index IN (2, 5, 14));

produces

    min    
-----------
  mAA m   +

⚠️ Note that there is a space character before m.

nrainer-materialize commented 5 months ago

Further similar case:

mz:

materialize=> select '0'::text::text < '-1'::text;
 ?column? 
----------
 f
(1 row)

materialize=> select '0'::text::text < '-'::text;
 ?column? 
----------
 f
(1 row)

pg

postgres=# select '0'::text::text < '-1'::text;
 ?column? 
----------
 t
(1 row)

postgres=# select '0'::text::text < '-'::text;
 ?column? 
----------
 f
(1 row)

According to @sploiselle,

This PG output inconsistency is due to the way Rust vs. Postgres perform ordering operations.