性能指标

更新时间:
复制 MD 格式

包含多表 Join、子查询、聚合与排序的复杂分析查询,在PostgreSQL行存上耗时较长:本次 TPC-H SF100 测试的 22 条查询中,Q9、Q17、Q20 三条在行存侧超时。列存索引(语法名 csi,也称 IMCI)面向此类查询,本文以 TPC-H SF100(100 GB)的数据表和 22 条标准 SQL 为例,给出从数据准备、创建列存索引到执行查询与结果对比的完整可复现流程。实测列存索引总耗时 14.784 秒,开箱参数 PostgreSQL 行存总耗时高于2006秒,按总耗时计算的加速比大于135倍,单条查询加速比区间为7倍至1168倍。

测试内容与数据量

TPC-H 作为业界常用的性能标准测试,由 TPC 委员会制定发布,用于评测数据库的分析能力。本次列存索引查询基础数据包含 8 张数据表,执行 22 条复杂 SQL 查询,查询语句包含单表统计、多表 Join、子查询、聚合、排序等类型。测试数据量为 TPC-H SF100(100 GB 级数据)。

说明

本文的TPC-H的实现基于TPC-H的基准测试,并不能与已发布的TPC-H基准测试结果相比较,本文中的测试并不完全符合TPC-H的所有要求。

测试环境

本次测试的环境配置如下:

  • PolarDB PostgreSQL版集群:

    • 数据库引擎:PostgreSQL 14。

    • 产品版本:企业版、独享规格。

    • 节点规格:32核256 GB。

环境准备

开始测试前,确认以下条件已满足。生成测试数据约需 30 分钟,单线程串行创建列存索引约需 39 分钟,可据此预留测试时间。

数据准备

数据准备包括编译 TPCH 工具、生成测试数据,并将数据导入测试数据库 tpchdb。按以下顺序执行:

  1. 解压并编译 dbgen 工具。

    # 解压
    tar -zxvf dbgen.tar.gz
    # 编译
    cd ./dbgen
    make -f makefile.suite
  2. 使用 TPCH 工具生成 100 GB 测试数据,预计执行时间约 30 分钟。

    # 切换到dbgen目录
    ./dbgen -s 100 -f
  3. 确认当前位于 dbgen 目录下,pwd 应返回 /<安装路径>/dbgen。

    # 确认所在目录
    pwd
  4. 在 ECS 实例上,使用PolarDB提供的数据库连接工具(PolarDB-Tools),通过命令行连接您的集群,目标数据库为 tpchdb。

    /u01/polardb_pg_tools/bin/psql  -h <集群地址> -p <集群地址对应端口> -U <高权限账号> -d tpchdb
  5. 导入测试数据。

    \i ./dss.ddl
    \copy part from ./part.tbl with delimiter as '|' NULL '';
    \copy region from ./region.tbl with delimiter as '|' NULL '';
    \copy nation from ./nation.tbl with delimiter as '|' NULL '';
    \copy orders from ./orders.tbl with delimiter as '|' NULL '';
    \copy customer from ./customer.tbl with delimiter as '|' NULL '';
    \copy lineitem from ./lineitem.tbl with delimiter as '|' NULL '';
    \copy partsupp from ./partsupp.tbl with delimiter as '|' NULL '';
    \copy supplier from ./supplier.tbl with delimiter as '|' NULL '';
  6. 核对 8 张表的导入结果,各表数据行数应与列存索引占用空间小节中列出的行数一致(合计 866,037,932 行)。若某张表导入失败,需重新导入该表数据后再执行后续步骤。

开启并创建列存索引

  1. 根据PolarDB PostgreSQL版集群版本开启列存索引。

  2. 为 8 张测试表创建列存索引。

    --partsupp表
    ALTER TABLE PARTSUPP ADD CONSTRAINT partsupp_pkey PRIMARY KEY (PS_PARTKEY, PS_SUPPKEY);
    CREATE INDEX imps ON partsupp USING csi(ps_partkey, ps_suppkey, ps_availqty, ps_supplycost, ps_comment);
    
    --part表
    ALTER TABLE PART ADD CONSTRAINT part_kpey PRIMARY KEY (P_PARTKEY);
    CREATE INDEX im_p ON part USING csi(p_partkey, p_name, p_mfgr, p_brand, p_type, p_size, p_container, p_retailprice, p_comment);
    
    --supplier表
    ALTER TABLE SUPPLIER ADD CONSTRAINT supplier_pkey PRIMARY KEY (S_SUPPKEY);
    CREATE INDEX im_s ON supplier USING csi(s_suppkey, s_name, s_address, s_nationkey, s_phone, s_acctbal, s_comment);
    
    --customer表
    ALTER TABLE CUSTOMER ADD CONSTRAINT customer_pkey PRIMARY KEY (C_CUSTKEY);
    CREATE INDEX im_c ON customer USING csi(c_custkey, c_name, c_address, c_nationkey, c_phone, c_acctbal, c_mktsegment, c_comment);
    
    --orders表
    ALTER TABLE ORDERS ADD CONSTRAINT orders_pkey PRIMARY KEY (O_ORDERKEY);
    CREATE INDEX im_o ON orders USING csi(o_orderkey, o_custkey, o_orderstatus, o_totalprice, o_orderdate, o_orderpriority, o_clerk, o_shippriority, o_comment);
    
    --lineitem表
    ALTER TABLE LINEITEM ADD CONSTRAINT lineitem_pkey PRIMARY KEY (L_ORDERKEY, L_LINENUMBER);
    CREATE INDEX im_l ON lineitem USING csi(l_orderkey, l_partkey, l_suppkey, l_linenumber, l_quantity, l_extendedprice, l_discount, l_tax, l_returnflag, l_linestatus, l_shipdate, l_commitdate, l_receiptdate, l_shipinstruct, l_shipmode, l_comment);
    
    --nation表
    ALTER TABLE NATION ADD CONSTRAINT nation_pkey PRIMARY KEY (N_NATIONKEY);
    CREATE INDEX im_n ON nation USING csi(n_nationkey, n_name, n_regionkey, n_comment);
    
    --region表
    ALTER TABLE REGION ADD CONSTRAINT region_pkey PRIMARY KEY (R_REGIONKEY);
    CREATE INDEX im_r ON region USING csi(r_regionkey, r_name, r_comment);
  3. 确认 8 张测试表的列存索引均已创建成功,再执行后续查询。

  4. 设置列存索引相关参数,便于后续查询。先在控制台的集群参数配置中将 polar_csi.exec_parallel 设置为 32,并按控制台提示使配置生效,然后在会话中执行以下命令。各参数的取值与生效方式见列存索引参数说明。

    SET polar_csi.enable_query TO ON;
    SET polar_csi.cost_threshold TO 0;
    说明

    polar_csi.memory_limit 是 SIGHUP 类参数,修改后需重载配置才能生效,不能在当前会话中使用 SET 修改。如需为测试调整内存上限,应在创建列存索引和开始测试前通过控制台配置,并按控制台提示完成参数重载或相关 Worker 重启。

执行 SQL 查询

在PolarDB PostgreSQL版集群内,依次执行 22 条复杂 SQL 查询并统计耗时。

  1. 执行查询前开启耗时统计。\timing 用于统计每条 SQL 语句的总计执行时间,必须开启后才能采集到耗时数据。

    \timing
  2. 依次执行22条查询。每条查询以 EXPLAIN ANALYZE 开头,输出执行计划与 Execution Time。\timing 统计的总计执行时间包含客户端往返开销,与 Execution Time 的数值不同,采集与对比耗时时需固定同一种口径,不可混用。

    单击展开查看22条SQL查询明细

    Q1

    EXPLAIN ANALYZE
    SELECT
        l_returnflag,
        l_linestatus,
        sum(l_quantity) as sum_qty,
        sum(l_extendedprice) as sum_base_price,
        sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
        sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
        avg(l_quantity) as avg_qty,
        avg(l_extendedprice) as avg_price,
        avg(l_discount) as avg_disc,
        count(*) as count_order
    FROM
        lineitem
    WHERE l_shipdate <= date '1998-12-01' - '60 day'::interval
    GROUP BY
        l_returnflag,
        l_linestatus
    ORDER BY
        l_returnflag,
        l_linestatus;

    Q2

    EXPLAIN ANALYZE
    SELECT
        s_acctbal,
        s_name,
        n_name,
        p_partkey,
        p_mfgr,
        s_address,
        s_phone,
        s_comment
    FROM
        part,
        supplier,
        partsupp,
        nation,
        region
    WHERE
        p_partkey = ps_partkey
        and s_suppkey = ps_suppkey
        and p_size = 43
        and p_type like '%NICKEL'
        and s_nationkey = n_nationkey
        and n_regionkey = r_regionkey
        and r_name = 'MIDDLE EAST'
        and ps_supplycost = (
        SELECT
        min(ps_supplycost)
        FROM
        partsupp,
        supplier,
        nation,
        region
        WHERE
        p_partkey = ps_partkey
        and s_suppkey = ps_suppkey
        and s_nationkey = n_nationkey
        and n_regionkey = r_regionkey
        and r_name = 'MIDDLE EAST'
        )
    ORDER BY
        s_acctbal desc,
        n_name,
        s_name,
        p_partkey limit 100;

    Q3

    EXPLAIN ANALYZE
    SELECT
        l_orderkey,
        sum(l_extendedprice * (1 - l_discount)) as revenue,
        o_orderdate,
        o_shippriority
    FROM
        customer,
        orders,
        lineitem
    WHERE
        c_mktsegment = 'FURNITURE'
        and c_custkey = o_custkey
        and l_orderkey = o_orderkey
        and o_orderdate < date '1995-03-05'
        and l_shipdate > date '1995-03-05'
    GROUP BY
        l_orderkey,
        o_orderdate,
        o_shippriority
    ORDER BY
        revenue desc,
        o_orderdate limit 100;

    Q4

    EXPLAIN ANALYZE
    SELECT
        o_orderpriority,
        count(*) as order_count
    FROM
        orders
    WHERE
        o_orderdate >= date '1993-05-01'
        and o_orderdate < date '1993-05-01' + interval '3 month'::interval
        and exists (
        SELECT
        *
        FROM
        lineitem
        WHERE
        l_orderkey = o_orderkey
        and l_commitdate < l_receiptdate
        )
    GROUP BY
        o_orderpriority
    ORDER BY
        o_orderpriority;

    Q5

    EXPLAIN ANALYZE
    SELECT
            n_name,
            sum(l_extendedprice * (1 - l_discount)) as revenue
    FROM
            customer,
            orders,
            lineitem,
            supplier,
            nation,
            region
    WHERE
            c_custkey = o_custkey
            and l_orderkey = o_orderkey
            and l_suppkey = s_suppkey
            and c_nationkey = s_nationkey
            and s_nationkey = n_nationkey
            and n_regionkey = r_regionkey
            and r_name = 'MIDDLE EAST'
            and o_orderdate >= date '1995-01-01'
            and o_orderdate < date '1995-01-01' + '1 year'::interval
    GROUP BY
            n_name
    ORDER BY
            revenue desc;

    Q6

    EXPLAIN ANALYZE
    SELECT
            sum(l_extendedprice * l_discount) as revenue
    FROM
            lineitem
    WHERE
            l_shipdate >= date '1993-01-01'
            and l_shipdate < date '1993-01-01' + '1 year'::interval
            and l_discount between 0.03 - 0.01 and 0.03 + 0.01
            and l_quantity < 24;

    Q7

    EXPLAIN ANALYZE
    SELECT
        supp_nation,
        cust_nation,
        l_year,
        sum(volume) AS revenue
    FROM (
        SELECT
            n1.n_name AS supp_nation,
            n2.n_name AS cust_nation,
            extract(year FROM l_shipdate) AS l_year,
            l_extendedprice * (1 - l_discount) AS volume
        FROM
            supplier,
            lineitem,
            orders,
            customer,
            nation n1,
            nation n2
        WHERE
            s_suppkey = l_suppkey
            AND o_orderkey = l_orderkey
            AND c_custkey = o_custkey
            AND s_nationkey = n1.n_nationkey
            AND c_nationkey = n2.n_nationkey
            AND ((n1.n_name = 'FRANCE'
                    AND n2.n_name = 'GERMANY')
                OR (n1.n_name = 'GERMANY'
                    AND n2.n_name = 'FRANCE'))
            AND l_shipdate BETWEEN CAST('1995-01-01' AS date)
            AND CAST('1996-12-31' AS date)) AS shipping
    GROUP BY
        supp_nation,
        cust_nation,
        l_year
    ORDER BY
        supp_nation,
        cust_nation,
        l_year;

    Q8

    EXPLAIN ANALYZE
    SELECT
            o_year,
            sum(case
                    when nation = 'INDONESIA' then volume
                    else 0
            end) / sum(volume) as mkt_share
    FROM
            (
                    SELECT
                            extract(year from o_orderdate) as o_year,
                            l_extendedprice * (1 - l_discount) as volume,
                            n2.n_name as nation
                    FROM
                            part,
                            supplier,
                            lineitem,
                            orders,
                            customer,
                            nation n1,
                            nation n2,
                            region
                    WHERE
                            p_partkey = l_partkey
                            and s_suppkey = l_suppkey
                            and l_orderkey = o_orderkey
                            and o_custkey = c_custkey
                            and c_nationkey = n1.n_nationkey
                            and n1.n_regionkey = r_regionkey
                            and r_name = 'ASIA'
                            and s_nationkey = n2.n_nationkey
                            and o_orderdate between '1995-01-01'::date and '1996-12-31'::date
                            and p_type = 'PROMO POLISHED NICKEL'
            ) as all_nations
    GROUP BY
            o_year
    ORDER BY
            o_year;

    Q9

    EXPLAIN ANALYZE
    SELECT
            nation,
            o_year,
            sum(amount) as sum_profit
    FROM
            (
                    SELECT
                            n_name as nation,
                            extract(year from o_orderdate) as o_year,
                            l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
                    FROM
                            part,
                            supplier,
                            lineitem,
                            partsupp,
                            orders,
                            nation
                    WHERE
                            s_suppkey = l_suppkey
                            and ps_suppkey = l_suppkey
                            and ps_partkey = l_partkey
                            and p_partkey = l_partkey
                            and o_orderkey = l_orderkey
                            and s_nationkey = n_nationkey
                            and p_name like '%navajo%'
            ) as profit
    GROUP BY
            nation,
            o_year
    ORDER BY
            nation,
            o_year desc limit 100;

    Q10

    EXPLAIN ANALYZE
    SELECT
            c_custkey,
            c_name,
            sum(l_extendedprice * (1 - l_discount)) as revenue,
            c_acctbal,
            n_name,
            c_address,
            c_phone,
            c_comment
    FROM
            customer,
            orders,
            lineitem,
            nation
    WHERE
            c_custkey = o_custkey
            and l_orderkey = o_orderkey
            and o_orderdate >= date '1993-08-01'
            and o_orderdate < date '1993-08-01' + '3 month'::interval
            and l_returnflag = 'R'
            and c_nationkey = n_nationkey
    GROUP BY
            c_custkey,
            c_name,
            c_acctbal,
            c_phone,
            n_name,
            c_address,
            c_comment
    ORDER BY
            revenue desc
            LIMIT 20;

    Q11

    EXPLAIN ANALYZE
    SELECT
            ps_partkey,
            sum(ps_supplycost * ps_availqty) as value
    FROM
            partsupp,
            supplier,
            nation
    WHERE
            ps_suppkey = s_suppkey
            and s_nationkey = n_nationkey
            and n_name = 'ALGERIA'
    GROUP BY
            ps_partkey having
                    sum(ps_supplycost * ps_availqty) > (
                            SELECT
                                    sum(ps_supplycost * ps_availqty) * 0.0001000000
                            FROM
                                    partsupp,
                                    supplier,
                                    nation
                            WHERE
                                    ps_suppkey = s_suppkey
                                    and s_nationkey = n_nationkey
                                    and n_name = 'ALGERIA'
                    )
    ORDER BY
            value desc;

    Q12

    EXPLAIN ANALYZE
    SELECT
            l_shipmode,
            sum(case
                    when o_orderpriority = '1-URGENT'
                            or o_orderpriority = '2-HIGH'
                            then 1
                    else 0
            end) as high_line_count,
            sum(case
                    when o_orderpriority <> '1-URGENT'
                            and o_orderpriority <> '2-HIGH'
                            then 1
                    else 0
            end) as low_line_count
    FROM
            orders,
            lineitem
    WHERE
            o_orderkey = l_orderkey
            and l_shipmode in ('AIR', 'FOB')
            and l_commitdate < l_receiptdate
            and l_shipdate < l_commitdate
            and l_receiptdate >= date '1996-01-01'
            and l_receiptdate < date '1996-01-01' + '1 year'::interval
    GROUP BY
            l_shipmode
    ORDER BY
            l_shipmode;

    Q13

    EXPLAIN ANALYZE
    SELECT
            c_count,
            count(*) as custdist
    FROM
            (
                    SELECT
                            c_custkey,
                            count(o_orderkey)
                    FROM
                            customer left outer join orders on
                                    c_custkey = o_custkey
                                    and o_comment not like '%pending%requests%'
                    GROUP BY
                            c_custkey
            ) as c_orders (c_custkey, c_count)
    GROUP BY
            c_count
    ORDER BY
            custdist desc,
            c_count desc;

    Q14

    EXPLAIN ANALYZE
    SELECT
            100.00 * sum(case
                    when p_type like 'PROMO%'
                            then l_extendedprice * (1 - l_discount)
                    else 0
            end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue
    FROM
            lineitem,
            part
    WHERE
            l_partkey = p_partkey
            and l_shipdate >= date '1995-02-01'
            and l_shipdate < date '1995-02-01' + interval '1 month'::interval;

    Q15

    EXPLAIN ANALYZE
    WITH revenue0 as (
        SELECT
        l_suppkey as supplier_no,
        sum(l_extendedprice * (1 - l_discount)) as total_revenue
        FROM
        lineitem
        WHERE
        l_shipdate >= date '1995-08-01'
        and l_shipdate < date '1995-08-01' + '3 month'::interval
        GROUP BY
        l_suppkey)
    SELECT
        s_suppkey,
        s_name,
        s_address,
        s_phone,
        total_revenue
    FROM
        supplier,
        revenue0
    WHERE
        s_suppkey = supplier_no
        and total_revenue = (
        SELECT
        max(total_revenue)
        FROM
        revenue0
        )
    ORDER BY
        s_suppkey;

    Q16

    EXPLAIN ANALYZE
    SELECT
            p_brand,
            p_type,
            p_size,
            count(distinct ps_suppkey) as supplier_cnt
    FROM
            partsupp,
            part
    WHERE
            p_partkey = ps_partkey
            and p_brand <> 'Brand#13'
            and p_type not like 'ECONOMY BRUSHED%'
            and p_size in (11, 8, 10, 31, 21, 13, 32, 28)
            and ps_suppkey not in (
                    SELECT
                            s_suppkey
                    FROM
                            supplier
                    WHERE
                            s_comment like '%Customer%Complaints%'
            )
    GROUP BY
            p_brand,
            p_type,
            p_size
    ORDER BY
            supplier_cnt desc,
            p_brand,
            p_type,
            p_size limit 100;

    Q17

    EXPLAIN ANALYZE
    SELECT
            sum(l_extendedprice) / 7.0 as avg_yearly
    FROM
            lineitem,
            part
    where
            p_partkey = l_partkey
            and p_brand = 'Brand#44'
            and p_container = 'MED PKG'
            and l_quantity < (
                    SELECT
                            0.2 * avg(l_quantity)
                    FROM
                            lineitem
                    WHERE
                            l_partkey = p_partkey
            );

    Q18

    EXPLAIN ANALYZE
    SELECT
            c_name,
            c_custkey,
            o_orderkey,
            o_orderdate,
            o_totalprice,
            sum(l_quantity)
    FROM
            customer,
            orders,
            lineitem
    WHERE
            o_orderkey in (
                    SELECT
                            l_orderkey
                    FROM
                            lineitem
                    GROUP BY
                            l_orderkey having
                                    sum(l_quantity) > 313
            )
            and c_custkey = o_custkey
            and o_orderkey = l_orderkey
    GROUP BY
            c_name,
            c_custkey,
            o_orderkey,
            o_orderdate,
            o_totalprice
    ORDER BY
            o_totalprice desc,
            o_orderdate limit 100;

    Q19

    EXPLAIN ANALYZE
    SELECT
            sum(l_extendedprice* (1 - l_discount)) as revenue
    FROM
            lineitem,
            part
    WHERE
            (
                    p_partkey = l_partkey
                    and p_brand = 'Brand#15'
                    and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
                    and l_quantity >= 10 and l_quantity <= 10 + 10
                    and p_size between 1 and 5
                    and l_shipmode in ('AIR', 'AIR REG')
                    and l_shipinstruct = 'DELIVER IN PERSON'
            )
            or
            (
                    p_partkey = l_partkey
                    and p_brand = 'Brand#45'
                    and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
                    and l_quantity >= 18 and l_quantity <= 18 + 10
                    and p_size between 1 and 10
                    and l_shipmode in ('AIR', 'AIR REG')
                    and l_shipinstruct = 'DELIVER IN PERSON'
            )
            or
            (
                    p_partkey = l_partkey
                    and p_brand = 'Brand#21'
                    and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
                    and l_quantity >= 30 and l_quantity <= 30 + 10
                    and p_size between 1 and 15
                    and l_shipmode in ('AIR', 'AIR REG')
                    and l_shipinstruct = 'DELIVER IN PERSON'
            );

    Q20

    EXPLAIN ANALYZE
    SELECT
            s_name,
            s_address
    FROM
            supplier,
            nation
    WHERE
            s_suppkey in (
                    SELECT
                            ps_suppkey
                    FROM
                            partsupp
                    WHERE
                            ps_partkey in (
                                    SELECT
                                            p_partkey
                                    FROM
                                            part
                                    WHERE
                                            p_name like 'lemon%'
                            )
                            AND ps_availqty > (
                                    SELECT
                                            0.5 * sum(l_quantity)
                                    FROM
                                            lineitem
                                    WHERE
                                            l_partkey = ps_partkey
                                            and l_suppkey = ps_suppkey
                                            and l_shipdate >= date '1997-01-01'
                                            and l_shipdate < date '1997-01-01' + '1 year'::interval
                            )
            )
            and s_nationkey = n_nationkey
            and n_name = 'INDONESIA'
    ORDER BY
            s_name limit 100;

    Q21

    EXPLAIN ANALYZE
    SELECT
            s_name,
            count(*) as numwait
    FROM
            supplier,
            lineitem l1,
            orders,
            nation
    WHERE
            s_suppkey = l1.l_suppkey
            and o_orderkey = l1.l_orderkey
            and o_orderstatus = 'F'
            and l1.l_receiptdate > l1.l_commitdate
            and exists (
                    SELECT
                            *
                    FROM
                            lineitem l2
                    WHERE
                            l2.l_orderkey = l1.l_orderkey
                            and l2.l_suppkey <> l1.l_suppkey
            )
            and not exists (
                    SELECT
                            *
                    FROM
                            lineitem l3
                    WHERE
                            l3.l_orderkey = l1.l_orderkey
                            and l3.l_suppkey <> l1.l_suppkey
                            and l3.l_receiptdate > l3.l_commitdate
            )
            and s_nationkey = n_nationkey
            and n_name = 'INDIA'
    GROUP BY
            s_name
    ORDER BY
            numwait desc,
            s_name limit 100;

    Q22

    EXPLAIN ANALYZE
    SELECT
            cntrycode,
            count(*) as numcust,
            sum(c_acctbal) as totacctbal
    FROM
            (
                    SELECT
                            substring(c_phone from 1 for 2) as cntrycode,
                            c_acctbal
                    FROM
                            customer
                    WHERE
                            substring(c_phone from 1 for 2) in
                                    ('16', '17', '24', '21', '19', '22', '15')
                            and c_acctbal > (
                                    SELECT
                                            avg(c_acctbal)
                                    FROM
                                            customer
                                    WHERE
                                            c_acctbal > 0.00
                                            and substring(c_phone from 1 for 2) in
                                                    ('16', '17', '24', '21', '19', '22', '15')
                            )
                            and not exists (
                                    SELECT
                                            *
                                    FROM
                                            orders
                                    WHERE
                                            o_custkey = c_custkey
                            )
            ) as custsale
    GROUP BY
            cntrycode
    ORDER BY
            cntrycode;

测试结果

创建列存索引耗时

测试结论:8 张表的列存索引以单线程串行方式创建,总耗时 39 分钟。该值为 8 张表的合计耗时,各表数据量差异较大(LINEITEM 为 600,037,902 行,REGION 为 5 行),不能按表数量等比外推到单表。

列存索引占用空间

测试结论:

  • PostgreSQL 行存(Heap 表)占用空间为 126 GB。

  • 列存索引占用空间:

    • 不包含主键时(polar_csi.enable_pk=false),总占用空间为 25 GB,为 PostgreSQL 行存Heap 表的 20%,适用于静态数据构建列存索引。

    • 包含主键时(polar_csi.enable_pk=true),总占用空间为 53 GB,为 PostgreSQL 行存Heap 表的 42%,适用于动态数据的列存索引。

    表名称

    表中包含的数据行数

    PostgreSQL 行存

    列存索引(不包含主键)

    列存索引(包含主键)

    LINEITEM

    600,037,902

    86 GB

    17 GB

    36 GB

    ORDERS

    150,000,000

    20 GB

    4406 MB

    9052 MB

    PARTSUPP

    80,000,000

    13 GB

    3452 MB

    6689 MB

    PART

    20,000,000

    3204 MB

    487 MB

    634 MB

    CUSTOMER

    15,000,000

    2808 MB

    992 MB

    1108 MB

    SUPPLIER

    1,000,000

    176 MB

    63 MB

    72 MB

    NATION

    25

    8 KB

    528 KB

    528 KB

    REGION

    5

    8 KB

    528 KB

    528 KB

    合计

    866,037,932

    126 GB

    25 GB

    53 GB

    表中各分项数值沿用测试输出的原始单位(GB、MB、KB),为四舍五入结果,合计按未取整的原始值统计,因此分项相加与合计可能存在差异。

查询性能

单位为秒。加速比为开箱参数 PostgreSQL 行存耗时除以列存索引耗时,大于 1 表示列存更快。Q9、Q17、Q20 三条查询在行存侧超时,统一按 500 秒计入总耗时,因此这三条查询的行存耗时、对应加速比以及合计行均为下界,表中以 ≥ 标注。

  • 两侧对比的参数口径如下:

    • 列存索引侧:polar_csi.exec_parallel 设置为 32(对应表头的 32 线程),并在会话中设置 polar_csi.enable_query=ON、polar_csi.cost_threshold=0。

    • PostgreSQL 行存侧:开箱参数,即未调整数据库参数,各参数的具体取值以产品实际默认为准。

  • 测试结论:

    • 列存索引总耗时:14.784 秒

    • 开箱参数 PostgreSQL 行存总耗时:≥2006.269 秒

    • 按总耗时计算的加速比:≥135.7 倍

    查询

    列存索引(32 线程)

    PostgreSQL 行存(开箱参数)

    加速比

    Q1

    0.863

    35.638

    41.30

    Q2

    0.162

    27.512

    169.83

    Q3

    0.544

    34.368

    63.18

    Q4

    0.432

    3.084

    7.14

    Q5

    0.617

    36.919

    59.84

    Q6

    0.144

    4.191

    29.10

    Q7

    0.429

    10.061

    23.45

    Q8

    0.420

    9.587

    22.83

    Q9

    1.883

    ≥500

    ≥265.53

    Q10

    0.833

    33.632

    40.37

    Q11

    0.183

    3.980

    21.75

    Q12

    0.486

    6.395

    13.16

    Q13

    1.429

    136.754

    95.70

    Q14

    0.393

    6.452

    16.42

    Q15

    0.808

    9.364

    11.59

    Q16

    0.318

    23.039

    72.45

    Q17

    0.483

    ≥500

    ≥1035.19

    Q18

    1.267

    98.083

    77.41

    Q19

    0.579

    7.447

    12.86

    Q20

    0.428

    ≥500

    ≥1168.22

    Q21

    1.723

    13.109

    7.61

    Q22

    0.360

    6.654

    18.48

    合计

    14.784

    ≥2006.269

    ≥135.7

    22 条查询的加速比跨越两个数量级,收益与行存侧耗时的量级直接相关。行存耗时在 23 秒以上的 8 条查询(Q1、Q2、Q3、Q5、Q10、Q13、Q16、Q18)加速比均在 40 倍以上,Q9、Q17、Q20 在行存侧超时。行存耗时在 14 秒以下的 11 条查询加速比在 7.14 倍至 29.10 倍之间。数据扫描量大、Join 与聚合规模大的分析型查询收益最高,行存侧已能在十余秒内返回的查询收益相对有限。评估业务收益时,可对照业务查询在行存侧的耗时落在上述哪个区间。

    performance-01-YdbNAA87

后续步骤

测试结束后,集群中保留 100 GB 的 TPC-H 测试数据(PostgreSQL 行存占用 126 GB)和最多 53 GB 的列存索引,ECS 实例上保留 dbgen 生成的 .tbl 数据文件。这些数据会持续占用存储空间并产生费用,按需完成清理:

  • 删除测试数据库 tpchdb 中的 TPC-H 数据表与列存索引,回收行存数据与列存索引占用的存储空间。

  • 删除 ECS 实例上 dbgen 目录下的 .tbl 文件,释放磁盘空间。