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 Error Bug] SELECT MAX(<column>) FROM table GROUP BY <column> HAVING <column> < MIN(<column>) Brings Errors #636

Closed
qwebug opened this issue Sep 3, 2023 · 4 comments
Labels
wait for confirmation developer solved this problem, and wait for confirmation by the user

Comments

@qwebug
Copy link

qwebug commented Sep 3, 2023

Describe:

Using SELECT MAX(<column>) FROM table GROUP BY <column> HAVING <column> < MIN(<column>) will report an error, when pg_strom.enabled is turned on.

However it is able to output result, when pg_strom.enabled is turned off.

Sql:

CREATE TABLE t0(c0 INT , c1 INT  PRIMARY KEY );
INSERT INTO t0(c1, c0) VALUES(1, 1);
CREATE SCHEMA extensions;
CREATE EXTENSION pg_strom WITH SCHEMA extensions;
set pg_strom.enabled=on;
SELECT MAX(c0) FROM t0 GROUP BY t0.c1 HAVING t0.c0<MIN(t0.c0);

Result:

ERROR:  Bug? referenced variable is grouping-key nor its dependent key: {VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnosyn 1 :varattnosyn 1 :location 45}

Sql:

set pg_strom.enabled=off;
SELECT MAX(c0) FROM t0 GROUP BY t0.c1 HAVING t0.c0<MIN(t0.c0);

Result:

 max 
-----
(0 rows)

Environment:

Pg-strom Version: commit b1a487b

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

CUDA Version: 12.0.1

NVIDIA Driver Version: 535.86.05

@kaigai
Copy link
Contributor

kaigai commented Sep 8, 2023

SELECT MAX(c0) FROM t0 GROUP BY t0.c1 HAVING t0.c0<MIN(t0.c0);

I'm not certain how this query should work, because t0.c0 is not a grouping-key, thus it shall not be appear at the post-group-by phase.
Right now, I have no idea about right direction of this issue. So, let me move the discussion to the pgsql-hackers.

@kaigai
Copy link
Contributor

kaigai commented Sep 8, 2023

kaigai added a commit that referenced this issue Sep 9, 2023
This commit fixes the issue reported at #636 and #637.

In the older version, aggregate function appeared only in HAVING
clause was ordered after the grouping-keys. It has no guarantee
the intermediate state is aligned to 64bit. Then, following
atomic operation might cause misaligned access.

Also, if grouping-key is the primary key, it means individual
tuples shall not be grouped. Thus, PostgreSQL allows to use
the columns that are not listed as grouping-keys.
@kaigai
Copy link
Contributor

kaigai commented Sep 9, 2023

6552e69f2ad521832eaefd7edd4a8ac808ec7cf1 fixes this problem.

This change allows to reference non-grouping-key columns in HAVING clause, if PostgreSQL allows the statement.

@kaigai kaigai added the wait for confirmation developer solved this problem, and wait for confirmation by the user label Sep 9, 2023
@qwebug
Copy link
Author

qwebug commented Sep 11, 2023

This problem is fixed, after my verification.
Thanks for your work.

@kaigai kaigai closed this as completed Sep 11, 2023
@qwebug qwebug changed the title [Error Bug] SELECT MAX(<column>) FROM table GROUP BY <column> HAVING <column> < MIN(<column>) Brings Errors [GPU Error Bug] SELECT MAX(<column>) FROM table GROUP BY <column> HAVING <column> < MIN(<column>) Brings Errors Jan 22, 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