heterodb/pg-strom

arrow_fdwでインデックスが有効になっているか確認出来ない

Closed this issue · 2 comments

pg2arrowでインデックス情報を付加したarrowファイルを出力→arrow_fdwでインポートし検索を行った際、インデックスが有効になっているか確認が出来ません。

pg2arrow --dumpにて、metadataにmin_value,max_valueがそれぞれ含まれていることは確認済みです。

CREATE TABLE arrow_index_data (
  id         int,
  date_num        date
);

INSERT INTO arrow_index_data (
    SELECT x,
        pgstrom.random_date(0)
    FROM generate_series(1,1000000) x);

 \! ~/pg-strom/arrow-tools/pg2arrow -s 4m --set=timezone:Asia/Tokyo -d postgres -c 'SELECT * FROM arrow_index_data ORDER BY date_num' -o /tmp/test_arrow_index.data --stat=date_num --p
rogress

 \! ~/pg-strom/arrow-tools/pg2arrow --dump  /tmp/test_arrow_index.data

IMPORT FOREIGN SCHEMA regtest_arrow
  FROM SERVER arrow_fdw
  INTO public
OPTIONS (file '/tmp/test_arrow_index.data');

EXPLAIN ANALYZE
SELECT * FROM public.regtest_arrow
 WHERE date_num='2019-04-14';

arrowファイル生成時のpg2arrowの出力

RecordBatch[0]: offset=448 length=4194632 (meta=200, body=4194432) nitems=524289
RecordBatch[1]: offset=4195080 length=3805896 (meta=200, body=3805696) nitems=475711

pg2arrow --dumpの出力

[Footer]
{Footer: version=V4, schema={Schema: endianness=little, fields=[{Field: name="id", nullable=true, type={Int32}, children=[], custom_metadata=[]}, {Field: name="date_num", nullable=true, type={Date: unit=day}, children=[], custom_metadata=[{KeyValue: key="min_values" value="16436,18544"}, {KeyValue: key="max_values" value="18544,20452"}]}], custom_metadata=[{KeyValue: key="sql_command" value="SELECT * FROM arrow_index_data ORDER BY date_num"}], features=[Unused]}, dictionaries=[], recordBatches=[{Block: offset=448, metaDataLength=200 bodyLength=4194432}, {Block: offset=4195080, metaDataLength=200 bodyLength=3805696}]}
[Record Batch 0]
{Block: offset=448, metaDataLength=200 bodyLength=4194432}
{Message: version=V4, body={RecordBatch: length=524289, nodes=[{FieldNode: length=524289, null_count=0}, {FieldNode: length=524289, null_count=0}], buffers=[{Buffer: offset=0, length=0}, {Buffer: offset=0, length=2097216}, {Buffer: offset=2097216, length=0}, {Buffer: offset=2097216, length=2097216}]}, bodyLength=4194432}
[Record Batch 1]
{Block: offset=4195080, metaDataLength=200 bodyLength=3805696}
{Message: version=V4, body={RecordBatch: length=475711, nodes=[{FieldNode: length=475711, null_count=0}, {FieldNode: length=475711, null_count=0}], buffers=[{Buffer: offset=0, length=0}, {Buffer: offset=0, length=1902848}, {Buffer: offset=1902848, length=0}, {Buffer: offset=1902848, length=1902848}]}, bodyLength=3805696}

EXPLAIN ANALYZEの出力結果

                                                            QUERY PLAN                                                            
----------------------------------------------------------------------------------------------------------------------------------
 Custom Scan (GpuScan) on regtest_arrow  (cost=100.00..1282.25 rows=5000 width=8) (actual time=272.204..273.378 rows=279 loops=1)
   GPU Projection: id, date_num
   GPU Scan Quals: (date_num = '2019-04-14'::date) [plan: 1000000 -> 5000, exec: 1000000 -> 279]
   referenced: id, date_num
   file0: /tmp/test_arrow_index.data (read: 7812.62KB, size: 7813.97KB)
   GPU-Direct SQL: disabled (GPU-0; vfs=977, ntuples=1000000)
 Planning Time: 0.447 ms
 Execution Time: 273.509 ms
(8 rows)

6cc098cd73f4077af6621fad15042d5ac18cc97b で修正です。

  • min/max統計情報が設定されている/設定されていないフラグが逆になっていた
  • VarがINDEX_VARを指しているため、cscan->custom_scan_tlist を参照して、元の列がどこなのかを特定せねばならなかった

確認しました。ありがとうございました。