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

[GPU Logic Bug] SELECT DISTINCT ON <column> FROM <table> WHERE <condition> Brings GPU Logic Bug #828

Open
qwebug opened this issue Oct 9, 2024 · 1 comment
Labels
wait for confirmation developer solved this problem, and wait for confirmation by the user

Comments

@qwebug
Copy link

qwebug commented Oct 9, 2024

Describe:

SELECT DISTINCT ON <column> FROM <table> WHERE <condition> brings different results, when using CPU-only configurations and GPU-used configurations.

SQL with CPU-only Config:

CREATE TABLE t2(c0 bigint UNIQUE PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY NOT NULL, c1 DECIMAL );
CREATE TABLE t3(LIKE t2);
INSERT INTO t2(c0, c1) VALUES(4, 0.8), (0, 0.02), (-1, 0.2);
INSERT INTO t3(c0, c1) VALUES(-1, 0.4);
INSERT INTO t3(c1, c0) VALUES(0.4, -1), (0.2, -2), (0.08, -1);
CREATE SCHEMA extensions;
CREATE EXTENSION pg_strom WITH SCHEMA extensions;
SET pg_strom.enabled=off;
SELECT DISTINCT ON (t2.c1) * FROM t3, t2 WHERE ((t3.c1)!=(t2.c1));

Result:

 c0 |  c1  | c0 |  c1  
----+------+----+------
 -1 |  0.4 |  0 | 0.02
 -1 | 0.08 | -1 |  0.2
 -2 |  0.2 |  4 |  0.8
(3 rows)

SQL with GPU-used Config:

SET pg_strom.enabled=on;
SELECT DISTINCT ON (t2.c1) * FROM t3, t2 WHERE ((t3.c1)!=(t2.c1));

Result:

 c0 |  c1  | c0 |  c1  
----+------+----+------
 -1 |  0.4 |  0 | 0.02
 -1 | 0.08 | -1 |  0.2
 -1 |  0.4 |  4 |  0.8
(3 rows)

Environment:

Pg-strom Version: commit 9765660

PostgreSQL Version: 15.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-20), 64-bit

CUDA Version: 12.2

NVIDIA Driver Version: 535.171.04

@kaigai
Copy link
Contributor

kaigai commented Oct 15, 2024

This is not a bug, but specification.
PG-Strom runs per-row evaluation in parallel, so GpuScan's results order is not guaranteed.
This query specifies DISTINCT ON (t2.c1), thus t2.c1 is unique but other columns are not expectational.

These values were come from the tuple which scceeded atomicCAS operation on the GPU result buffer, and this behavior is not illigal.

@kaigai kaigai added the wait for confirmation developer solved this problem, and wait for confirmation by the user label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wait for confirmation developer solved this problem, and wait for confirmation by the user
Projects
None yet
Development

No branches or pull requests

2 participants