tds-fdw / tds_fdw

A PostgreSQL foreign data wrapper to connect to TDS databases (Sybase and Microsoft SQL Server)
Other
381 stars 102 forks source link

mergejoin input data is out of order #372

Open nmoreaud opened 1 day ago

nmoreaud commented 1 day ago

This query fails:

SELECT u.*
FROM user_account u
join user_account u2 ON u2.name = u.name
ORDER BY u.name;

Error message: mergejoin input data is out of order. I guess that the order of "James" and "JAmes" is not well defined.

The same error happen on more complex requests with CTE. Depending on the real data and query, sometimes I do not see the error with DBeaver (it displays only the 200 first rows by default).

Versions

Docker image postgis/postgis
apt install postgresql-17-tds-fdw

PostgreSQL 17.1 (Debian 17.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit

tds_fdw | 2.0.4  

ii  freetds-common                     1.2.3-1                        all          configuration files for FreeTDS SQL client libraries

Microsoft SQL Server 2019 (RTM-GDR) (KB5046859) - 15.0.2130.3 (X64) 
    Oct 18 2024 15:25:23 
    Copyright (C) 2019 Microsoft Corporation
    Express Edition (64-bit) on Windows 10 Pro 10.0 <X64> (Build 22621: ) (Hypervisor)

Sentences, data structures, data

MSSQL:

CREATE DATABASE test;
CREATE TABLE user_account (
    ID int UNIQUE,
    NAME varchar(255)
);
insert into user_account(id, name) values (4, 'James'), (9, 'Thomas'), (7, 'Bhilal'), (15, 'JAmes');

Postgres:

CREATE EXTENSION if not exists tds_fdw;
CREATE server mssql_fdw_db
FOREIGN DATA WRAPPER tds_fdw
OPTIONS (servername 'windows-host', port '1433', database 'test', tds_version '7.1');

CREATE USER MAPPING FOR postgres
SERVER mssql_fdw_db
OPTIONS (username '...', password '...');

IMPORT FOREIGN SCHEMA dbo
FROM SERVER mssql_fdw_db
INTO public;