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

[VTJ-JP]Aggregate function(MAX()) does not return correct values. #847

Open
sakaik opened this issue Oct 25, 2024 · 0 comments
Open

[VTJ-JP]Aggregate function(MAX()) does not return correct values. #847

sakaik opened this issue Oct 25, 2024 · 0 comments

Comments

@sakaik
Copy link

sakaik commented Oct 25, 2024

Summary

 PG-Strom有効時に、MAX()関数が正しい値を返しません。
実行計画で、HashAggregate が選択された時にのみ発生しているように見えます。

具体例

このようなデータ(7200件)に対して、

db=# SELECT * FROM maxtest LIMIT 5;
 no | ymd |    val    
----+-----+-----------
 1  |   1 |   1.93425
 1  |   1 | 1.0846875
 1  |   1 |  1.571875
 1  |   1 |   0.31325
 1  |   1 | 0.7969375

以下の集約関数を含むクエリを実行したところ、極小の負数(正しくない)が返ってきました。

db=# SELECT no, ymd, MAX(val) 
  FROM maxtest
 GROUP BY no, ymd LIMIT 3;
 no | ymd |           max            
----+-----+--------------------------
 4  |   3 | -1.7976931348623157e+308
 4  |   1 | -1.7976931348623157e+308
 1  |   7 | -1.7976931348623157e+308

期待する結果

 PG-Stromオフ時には以下の結果となり、これが期待する値です。

db=# SET pg_strom.enabled=false;

db=# SELECT no, ymd, MAX(val) 
  FROM maxtest
 GROUP BY no, ymd LIMIT 3;
 no | ymd |    max    
----+-----+-----------
 4  |   3 |   1.98625
 4  |   1 |     2.033
 1  |   7 | 2.0410625

実行計画

EXPLAIN ANALYZE
SELECT no, ymd, MAX(val) 
  FROM maxtest
 GROUP BY no, ymd;
                                                           QUERY PLAN                                                            
---------------------------------------------------------------------------------------------------------------------------------
 HashAggregate  (cost=143.25..143.88 rows=50 width=14) (actual time=470.214..470.228 rows=50 loops=1)
   Group Key: no, ymd
   Batches: 1  Memory Usage: 24kB
   ->  Custom Scan (GpuPreAgg) on maxtest  (cost=142.38..142.88 rows=50 width=38) (actual time=470.164..470.177 rows=50 loops=1)
         GPU Projection: pgstrom.pmax(val), no, ymd
         GPU-Direct SQL: enabled (N=1,GPU0-0; buffer=39, ntuples=7200)
 Planning Time: 0.152 ms
 Execution Time: 470.353 ms

再現データ作成方法

テーブル

-- DROP TABLE maxtest;
CREATE TABLE maxtest (
  no varchar(10),
  ymd integer,
  val double precision);

データ

 以下のbashスクリプトにて 7200件のデータを生成します。
(DB_NAMEは環境に合わせて変更してください)

DB_NAME=mydb

for no in {1..5};do 
  for ymd in {1..10};do
    for h in {1..144};do
     echo "INSERT INTO maxtest VALUES ($no, $ymd, $RANDOM/16000.0);";
    done;
  done;
done | psql -Upostgres ${DB_NAME}

確認バージョン

db=# select pgstrom.githash();
                 githash                  
------------------------------------------
 81792828fff930b838b3e4b7f33650fd97c4a3cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant