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

PG17: SELECT distinct のEXPLAINのnrowsが実行のたびに変動する #814

Open
0-kaz opened this issue Jul 19, 2024 · 1 comment
Open

Comments

@0-kaz
Copy link
Contributor

0-kaz commented Jul 19, 2024

SELECT distinctを含むクエリのEXPLAIN出力中にあるnrowsの行数が実行のたびに変わってしまう。
再現性が低い現象であったがVACUUM ANALYZEを直前に実行すると100%再現することを確認。

実行計画:

1回目

Sort
Output: customer.c_nation, lineorder.lo_orderpriority
Sort Key: customer.c_nation, lineorder.lo_orderpriority
-> HashAggregate
Output: customer.c_nation, lineorder.lo_orderpriority
Group Key: customer.c_nation, lineorder.lo_orderpriority
-> Custom Scan (GpuPreAgg) on public.lineorder
Output: customer.c_nation, lineorder.lo_orderpriority
GPU Projection: customer.c_nation, lineorder.lo_orderpriority
GPU Scan Quals: (lineorder.lo_shipmode = 'AIR'::bpchar) [rows: 6001260 -> 874784]
GPU Join Quals [1]: (lineorder.lo_custkey = customer.c_custkey) ... [nrows: 874784 -> 174724]

2回目

Sort
Output: customer.c_nation, lineorder.lo_orderpriority
Sort Key: customer.c_nation, lineorder.lo_orderpriority
-> HashAggregate
Output: customer.c_nation, lineorder.lo_orderpriority
Group Key: customer.c_nation, lineorder.lo_orderpriority
-> Custom Scan (GpuPreAgg) on public.lineorder
Output: customer.c_nation, lineorder.lo_orderpriority
GPU Projection: customer.c_nation, lineorder.lo_orderpriority
GPU Scan Quals: (lineorder.lo_shipmode = 'AIR'::bpchar) [rows: 6001260 -> 845177]
GPU Join Quals [1]: (lineorder.lo_custkey = customer.c_custkey) ... [nrows: 845177 -> 174724]

データ投入

DROP TABLE IF EXISTS customer;
CREATE TABLE customer (
    c_custkey   integer NOT NULL,
    c_name      character varying(25),
    c_address   character varying(25),
    c_city      character(10),
    c_nation    character(15),
    c_region    character(12),
    c_phone     character(15),
    c_mktsegment character(10)
);

DROP TABLE IF EXISTS lineorder;
CREATE TABLE lineorder (
    lo_orderkey     bigint,
    lo_linenumber   integer,
    lo_custkey      integer,
    lo_partkey      integer,
    lo_suppkey      integer,
    lo_orderdate    integer,
    lo_orderpriority character(15),
    lo_shippriority character(1),
    lo_quantity     numeric,
    lo_extendedprice numeric,
    lo_ordertotalprice numeric,
    lo_discount     numeric,
    lo_revenue      numeric,
    lo_supplycost   numeric,
    lo_tax          numeric,
    lo_commit_date  character(8),
    lo_shipmode     character(10)
);

\copy customer  FROM PROGRAM './ssbm/dbgen-ssbm -s 1 -X -Tc' DELIMITER '|'
\copy lineorder FROM PROGRAM './ssbm/dbgen-ssbm -s 1 -X -Tl' DELIMITER '|'

再現クエリ(VACUUM ANALYZEを直前に実行すると100%再現)

VACUUM ANALYZE;
explain (verbose, costs off)
SELECT * FROM reference EXCEPT select distinct c_nation, lo_orderpriority
  from lineorder, customer
 where lo_custkey = c_custkey
   and c_region = 'AMERICA'
   and lo_shipmode = 'AIR'
 order by c_nation, lo_orderpriority;
@0-kaz 0-kaz mentioned this issue Aug 16, 2024
@kaigai
Copy link
Contributor

kaigai commented Oct 21, 2024

これ、最新版のPG-Stromだと再現しなくなってますね・・・。
(今日、何回かregression testを流しても、ココで引っかからなかった)

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

2 participants