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 <column> FROM <table> JOIN <table> WHERE <condition> Brings GPU Logic Bug #781

Closed
qwebug opened this issue Jun 5, 2024 · 1 comment
Labels
wait for confirmation developer solved this problem, and wait for confirmation by the user

Comments

@qwebug
Copy link

qwebug commented Jun 5, 2024

Describe:

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

SQL with CPU-only Config:

CREATE TABLE t0(c0 smallint);
CREATE TABLE t2(LIKE t0);
INSERT INTO t0(c0) VALUES(1), (3), (4), (0);
INSERT INTO t2(c0) VALUES(2), (1), (0), (5), (1), (0);
CREATE SCHEMA extensions;
CREATE EXTENSION pg_strom WITH SCHEMA extensions;
SET pg_strom.enabled=off;
SELECT t0.c0 FROM t0 CROSS JOIN t2 WHERE ((((t0.c0)IS NOT DISTINCT FROM(t2.c0)))AND((t0.c0) BETWEEN SYMMETRIC (- (t2.c0)) AND (1)));

Result:

 c0 
----
  1
  0
  1
  0
(4 rows)

SQL with GPU-used Config:

BEGIN;
SET LOCAL pg_strom.enabled=on; 
SET LOCAL pg_strom.enable_gpuscan=on; 
SET LOCAL pg_strom.enable_gpuhashjoin=on; 
SET LOCAL pg_strom.enable_gpujoin=on;
SELECT t0.c0 FROM t0 CROSS JOIN t2 WHERE ((((t0.c0)IS NOT DISTINCT FROM(t2.c0)))AND((t0.c0) BETWEEN SYMMETRIC (- (t2.c0)) AND (1)));
COMMIT;

Result:

 c0 
----
  1
  1
  0
  0
(4 rows)

Environment:

Pg-strom Version: commit b1f04e4

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 Jun 14, 2024

It is not a bug but by design.

SQL does not guarantee the order of results unless an explicit ORDER BY is not attached.

See the following results.
The result rows with c0=1 come from (0,1) (0,2) and (0,1) (0,5) pair, and the rows with c0=0 come from (0,4) (0,3) and (0,4) (0,6).

hoge=# set pg_strom.enabled = off;
SET
hoge=# SELECT t0.ctid, t2.ctid, t0.c0 FROM t0 CROSS JOIN t2 WHERE ((((t0.c0)IS NOT DISTINCT FROM(t2.c0)))AND((t0.c0) BETWEEN SYMMETRIC (- (t2.c0)) AND (1)));
 ctid  | ctid  | c0
-------+-------+----
 (0,1) | (0,2) |  1
 (0,4) | (0,3) |  0
 (0,1) | (0,5) |  1
 (0,4) | (0,6) |  0
(4 rows)
hoge=# set pg_strom.enabled = on;
SET
hoge=# SELECT t0.ctid, t2.ctid, t0.c0 FROM t0 CROSS JOIN t2 WHERE ((((t0.c0)IS NOT DISTINCT FROM(t2.c0)))AND((t0.c0) BETWEEN SYMMETRIC (- (t2.c0)) AND (1)));
 ctid  | ctid  | c0
-------+-------+----
 (0,1) | (0,2) |  1
 (0,1) | (0,5) |  1
 (0,4) | (0,3) |  0
 (0,4) | (0,6) |  0
(4 rows)

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