SSB benchmark performance test

Updated at:
Copy as MD

This topic explains how to use the Star Schema Benchmark (SSB) to test the performance of AnalyticDB for PostgreSQL and provides the test results.

SSB

The Star Schema Benchmark (SSB) is a test suite based on a star schema that is widely used in academia and industry. It lets you compare the baseline performance of various Online Analytical Processing (OLAP) products. By flattening the star schema into a single flat table, SSB serves as a benchmark for evaluating the aggregate query performance of a columnar storage engine. For more information, see the SSB paper.

Test

  • This test uses a 100 GB dataset. Use eight segment nodes, each with 2 cores and 16 GB of memory.

  • To test a 1 TB dataset, use 48 segment nodes, each with 2 cores and 16 GB of memory. This configuration uses more compute nodes to leverage the advantages of the MPP architecture.

Test results

The following table shows the test results of running 13 standard test SQL queries on the 100 GB SSB dataset.

Query

Execution time (s)

Q1.1

0.17

Q1.2

0.03

Q1.3

0.20

Q2.1

0.69

Q2.2

0.51

Q2.3

0.38

Q3.1

0.97

Q3.2

0.74

Q3.3

0.42

Q3.4

0.04

Q4.1

1.11

Q4.2

0.39

Q4.3

0.26

Total

5.91

Prerequisites

Procedure

Step 1: Create an instance

  1. Create an AnalyticDB for PostgreSQL instance. For more information, see Create an instance.

    The following table lists the instance specifications for the 100 GB test.

    Parameter

    Value

    Instance resource type

    elastic storage mode

    Instance series

    high availability

    Engine version

    7.0 Standard Edition

    Node specification (segment)

    2C16G

    Number of nodes

    8

    Storage disk type

    ESSD PL1

    Node storage capacity

    200 GB

    Database kernel version

    v7.4.2.1 or later

  2. Add the IP address of the ECS instance to the IP allowlist of the AnalyticDB for PostgreSQL instance.

Note
  • For a 100 GB test, use eight nodes (2 cores and 16 GB of memory each). For a 1 TB test, use 48 nodes (2 cores and 16 GB of memory each).

  • Recommendation: Due to resource limitations in some availability zones, run the test in zones with sufficient resources, such as China (Zhangjiakou), China (Hangzhou) Zone J, or China (Beijing) Zone I.

  • After the instance is created, you can upgrade it to v7.4.2.1 or later in the console.

Step 2: Generate test data

  1. Download the official SSB data generation tool and compile it.

    git clone https://github.com/vadimtk/ssb-dbgen.git
    cd ssb-dbgen
    make
  2. Generate 100 GB of SSB data.

    Important
    • The -s parameter specifies the data volume in GB.

    • The -C parameter specifies the number of file chunks. Set this parameter to an integer multiple of the number of segment nodes (compute nodes) in your cluster. For example, set the value to 16 for a 100 GB test or 96 for a 1 TB test.

    In the ssb-dbgen directory, run the following script to generate data in parallel:

    --Generate 100GB SSB Benchmark data
    for((i=1;i<=16;i++));
    do
    ./dbgen -s 100 -S $i -C 16 -f -T l &
    if [ $(($i%16)) -eq 0 ] # Generate 16 subfiles in parallel at a time
    then
            wait
            echo $i
    fi
    done
    
    ./dbgen -s 100 -T p
    ./dbgen -s 100 -T c
    ./dbgen -s 100 -T s
  3. Upload the generated data to OSS.

    If this is the first time you are using OSS, see ossutil command-line tool 1.0 to install and configure the ossutil tool. Then, run the following command to upload the data to OSS:

    ./ossutil64 cp -r <path_to_your_test_data> <your_oss_bucket_path> --exclude "*.tbl*"

    Example:

    ./ossutil64 cp -r /mnt/dbqgen/ oss://adbpg --exclude "*.tbl*"

Step 3: Create data tables

To create the final flat table for the SSB test, you first join multiple base tables. The following statements create these base tables.

CREATE TABLE customer
(
  C_CUSTKEY       int,
  C_NAME          text,
  C_ADDRESS       text,
  C_CITY          text,
  C_NATION        text,
  C_REGION        text,
  C_PHONE         text,
  C_MKTSEGMENT    text
)
using beam
with(compresstype=auto, compresslevel=1)
DISTRIBUTED BY(C_CUSTKEY)
ORDER BY (C_CUSTKEY);

CREATE TABLE lineorder
(
  LO_ORDERKEY             bigint,
  LO_LINENUMBER           int,
  LO_CUSTKEY              int,
  LO_PARTKEY              int,
  LO_SUPPKEY              int,
  LO_ORDERDATE            Date,
  LO_ORDERPRIORITY        text,
  LO_SHIPPRIORITY         int,
  LO_QUANTITY             int,
  LO_EXTENDEDPRICE        int,
  LO_ORDTOTALPRICE        int,
  LO_DISCOUNT             int,
  LO_REVENUE              int,
  LO_SUPPLYCOST           int,
  LO_TAX                  int,
  LO_COMMITDATE           Date,
  LO_SHIPMODE             text
)
using beam
with(compresstype=auto,compresslevel=1)
DISTRIBUTED BY(LO_ORDERKEY)
ORDER BY (LO_ORDERDATE, LO_ORDERKEY);

CREATE TABLE part
(
  P_PARTKEY       int,
  P_NAME          text,
  P_MFGR          text,
  P_CATEGORY      text,
  P_BRAND         text,
  P_COLOR         text,
  P_TYPE          text,
  P_SIZE          int,
  P_CONTAINER     text
)
using beam
with(compresstype=auto,compresslevel=1)
DISTRIBUTED BY(P_PARTKEY)
ORDER BY (P_PARTKEY);

CREATE TABLE supplier
(
  S_SUPPKEY       int,
  S_NAME          text,
  S_ADDRESS       text,
  S_CITY          text,
  S_NATION        text,
  S_REGION        text,
  S_PHONE         text
)
using beam
with(compresstype=auto,compresslevel=1)
DISTRIBUTED BY(S_SUPPKEY)
ORDER BY (S_SUPPKEY);

Step 4: Create OSS foreign tables and import data

Create OSS foreign tables to import the test data from OSS. For more information, see Use OSS foreign tables for data lake analytics.

CREATE SERVER oss_serv
    FOREIGN DATA WRAPPER oss_fdw
    OPTIONS (
        endpoint 'oss-xxx.aliyuncs.com',
        bucket 'xxxx'
  );
CREATE USER MAPPING FOR PUBLIC  SERVER oss_serv OPTIONS ( id 'xxxx', key 'xxx' );

CREATE FOREIGN TABLE ext_customer
(
  C_CUSTKEY       int,
  C_NAME          text,
  C_ADDRESS       text,
  C_CITY          text,
  C_NATION        text,
  C_REGION        text,
  C_PHONE         text,
  C_MKTSEGMENT    text
)
server oss_serv
    options (
        prefix 'ssb100g/customer_',
        format 'csv',
        DELIMITER '|'
    );

CREATE FOREIGN TABLE ext_lineorder
(
  LO_ORDERKEY             bigint,
  LO_LINENUMBER           int,
  LO_CUSTKEY              int,
  LO_PARTKEY              int,
  LO_SUPPKEY              int,
  LO_ORDERDATE            Date,
  LO_ORDERPRIORITY        text,
  LO_SHIPPRIORITY         int,
  LO_QUANTITY             int,
  LO_EXTENDEDPRICE        int,
  LO_ORDTOTALPRICE        int,
  LO_DISCOUNT             int,
  LO_REVENUE              int,
  LO_SUPPLYCOST           int,
  LO_TAX                  int,
  LO_COMMITDATE           Date,
  LO_SHIPMODE             text
)
server oss_serv
    options (
        prefix 'ssb100g/lineorder_',
        format 'csv',
        DELIMITER '|'
    );

CREATE FOREIGN TABLE ext_part
(
  P_PARTKEY       int,
  P_NAME          text,
  P_MFGR          text,
  P_CATEGORY      text,
  P_BRAND         text,
  P_COLOR         text,
  P_TYPE          text,
  P_SIZE          int,
  P_CONTAINER     text
)
server oss_serv
    options (
        prefix 'ssb100g/part_',
        format 'csv',
        DELIMITER '|'
    );

CREATE FOREIGN TABLE ext_supplier
(
  S_SUPPKEY       int,
  S_NAME          text,
  S_ADDRESS       text,
  S_CITY          text,
  S_NATION        text,
  S_REGION        text,
  S_PHONE         text
)
server oss_serv
    options (
        prefix 'ssb100g/supplier_',
        format 'csv',
        DELIMITER '|'
    );

-- Import data.
insert into part select * from ext_part;
insert into supplier select * from ext_supplier;
insert into customer select * from ext_customer;
insert into lineorder select * from ext_lineorder;

-- Drop the foreign tables.
drop external table ext_part;
drop external table ext_supplier;
drop external table ext_customer;
drop external table ext_lineorder;

Step 5: Generate the flat table

Join the four base tables to generate the SSB flat table lineorder_flat.

  1. Create the lineorder_flat table and import data into it.

    CREATE TABLE lineorder_flat
    (
      LO_ORDERKEY             bigint not null,
      LO_LINENUMBER           int not null,
      LO_CUSTKEY              int not null,
      LO_PARTKEY              int not null,
      LO_SUPPKEY              int not null,
      LO_ORDERDATE            Date not null,
      LO_ORDERPRIORITY        text not null,
      LO_SHIPPRIORITY         int not null,
      LO_QUANTITY             int not null,
      LO_EXTENDEDPRICE        int not null,
      LO_ORDTOTALPRICE        int not null,
      LO_DISCOUNT             int not null,
      LO_REVENUE              int not null,
      LO_SUPPLYCOST           int not null,
      LO_TAX                  int not null,
      LO_COMMITDATE           Date not null,
      LO_SHIPMODE             text not null,
      C_NAME                  text not null,
      C_ADDRESS               text not null,
      C_CITY                  text not null,
      C_NATION                text not null,
      C_REGION                text not null,
      C_PHONE                 text not null,
      C_MKTSEGMENT            text not null,
      S_NAME                  text not null,
      S_ADDRESS               text not null,
      S_CITY                  text not null,
      S_NATION                text not null,
      S_REGION                text not null,
      S_PHONE                 text not null,
      P_NAME                  text not null,
      P_MFGR                  text not null,
      P_CATEGORY              text not null,
      P_BRAND                 text not null,
      P_COLOR                 text not null,
      P_TYPE                  text not null,
      P_SIZE                  int not null,
      P_CONTAINER             text not null
    )
    using beam
    with(compresstype=auto, compresslevel=1)
    DISTRIBUTED BY(LO_ORDERKEY)
    ORDER BY(LO_ORDERDATE, LO_ORDERKEY);
    
    
    INSERT INTO lineorder_flat
    SELECT
        l.LO_ORDERKEY AS LO_ORDERKEY,
        l.LO_LINENUMBER AS LO_LINENUMBER,
        l.LO_CUSTKEY AS LO_CUSTKEY,
        l.LO_PARTKEY AS LO_PARTKEY,
        l.LO_SUPPKEY AS LO_SUPPKEY,
        l.LO_ORDERDATE AS LO_ORDERDATE,
        l.LO_ORDERPRIORITY AS LO_ORDERPRIORITY,
        l.LO_SHIPPRIORITY AS LO_SHIPPRIORITY,
        l.LO_QUANTITY AS LO_QUANTITY,
        l.LO_EXTENDEDPRICE AS LO_EXTENDEDPRICE,
        l.LO_ORDTOTALPRICE AS LO_ORDTOTALPRICE,
        l.LO_DISCOUNT AS LO_DISCOUNT,
        l.LO_REVENUE AS LO_REVENUE,
        l.LO_SUPPLYCOST AS LO_SUPPLYCOST,
        l.LO_TAX AS LO_TAX,
        l.LO_COMMITDATE AS LO_COMMITDATE,
        l.LO_SHIPMODE AS LO_SHIPMODE,
        c.C_NAME AS C_NAME,
        c.C_ADDRESS AS C_ADDRESS,
        c.C_CITY AS C_CITY,
        c.C_NATION AS C_NATION,
        c.C_REGION AS C_REGION,
        c.C_PHONE AS C_PHONE,
        c.C_MKTSEGMENT AS C_MKTSEGMENT,
        s.S_NAME AS S_NAME,
        s.S_ADDRESS AS S_ADDRESS,
        s.S_CITY AS S_CITY,
        s.S_NATION AS S_NATION,
        s.S_REGION AS S_REGION,
        s.S_PHONE AS S_PHONE,
        p.P_NAME AS P_NAME,
        p.P_MFGR AS P_MFGR,
        p.P_CATEGORY AS P_CATEGORY,
        p.P_BRAND AS P_BRAND,
        p.P_COLOR AS P_COLOR,
        p.P_TYPE AS P_TYPE,
        p.P_SIZE AS P_SIZE,
        p.P_CONTAINER AS P_CONTAINER
    FROM lineorder AS l
    INNER JOIN customer AS c ON c.C_CUSTKEY = l.LO_CUSTKEY
    INNER JOIN supplier AS s ON s.S_SUPPKEY = l.LO_SUPPKEY
    INNER JOIN part AS p ON p.P_PARTKEY = l.LO_PARTKEY;
    
    ANALYZE lineorder_flat;
    FLUSH lineorder_flat;
  2. Collect statistics and flush data to disk.

    ANALYZE lineorder_flat;
    FLUSH lineorder_flat;
  3. Run the following query. Proceed with the test only after the query returns no rows, which confirms that all background tasks are complete.

    select datname, query, state from pg_stat_activity 
      where state <> 'idle' and backend_type like '%autovacuum%';

The following table lists the row counts for each table in the 100 GB dataset.

Table name

Row count

customer

3,000,000

lineorder

600,037,902

part

1,400,000

supplier

200,000

lineorder_flat

600,037,902

Step 6: Apply configurations

ALTER DATABASE your_db set laser.enable_vectorized_engine to on;
ALTER DATABASE your_db set statement_mem = '16GB';

Step 7: Run the test

The SSB benchmark includes 13 standard SQL queries (Appendix: SSB test SQL) in four groups: Q1, Q2, Q3, and Q4.

  1. The test directory has the following structure:

    benchmark/
    ├── benchmark.sh
    └── query/
        ├── q1.sql
        ├── q2.sql
        ├── ...
        └── q13.sql
    • Save the following test script as benchmark/benchmark.sh.

      #!/bin/bash
      
      usage() {
        cat <<EOF
      Usage:
        $0 <database> <round> <host>
      
      Params:
        database  Required. The database name.
        round     Required. The number of rounds to run (a positive integer).
        host      Required. The database host address, such as 127.0.0.1 or a hostname.
      
      Examples:
        # Run 3 rounds on the local adbpg instance
        $0 tpcds_db 3 127.0.0.1
      
        # Run 1 round on a remote host
        $0 tpcds_db 1 10.0.0.5
      EOF
      }
      
      # Parameters: $1=database, $2=round, $3=host
      DATABASE="$1"
      ROUND="${2:-1}"
      HOST="$3"
      
      # Check parameters.
      if [ -z "$DATABASE" ] || [ -z "$ROUND" ] || [ -z "$HOST" ]; then
        usage
        exit 1
      fi
      
      echo "Database: $DATABASE"
      echo "Round: $ROUND"
      echo "Host: $HOST"
      
      HOME_PATH=$(pwd)
      QUERY_PATH="$HOME_PATH/query/"
      LOG_PATH="$HOME_PATH/log/"
      mkdir -p "$LOG_PATH"
      
      timestamp=$(date +%Y%m%d_%H%M%S)
      log_file="$HOME_PATH/tpcds_query_rt_${timestamp}.csv"
      echo "query,cost,total_cost" > "$log_file"
      
      total_cost=0
      for ((i=1; i<=99; i++)); do
          last_cost=0
          for ((r=1; r<=ROUND; r++)); do
              echo "begin run TPC-DS Q${i} round ${r}/$ROUND on adbpg (db: $DATABASE, host: $HOST), $(date)"
              begin_time=$(date +%s.%N)
      
              psql -h "$HOST" -d "$DATABASE" -f "$QUERY_PATH/q$i.sql" > "$LOG_PATH/log${i}_r${r}.out"
              rc=$?
      
              end_time=$(date +%s.%N)
              last_cost=$(awk "BEGIN {print $end_time - $begin_time}")
              if [ $rc -ne 0 ] ; then
                  printf "run TPC-DS Q%s round %s on adbpg fail, cost: %.2f, %s\n" "$i" "$r" "$last_cost" "$(date)"
              else
                  printf "run TPC-DS Q%s round %s on adbpg succ, cost: %.2f, %s\n" "$i" "$r" "$last_cost" "$(date)"
              fi
          done
          cost=$last_cost
          total_cost=$(awk "BEGIN {print $total_cost + $cost}")
          printf "TPC-DS Q%s final (round %d): cost: %.2f, totalCost: %.2f, %s\n" "$i" "$ROUND" "$cost" "$total_cost" "$(date)"
          printf "Q%s,%.2f,%.2f\n" "$i" "$cost" "$total_cost" >> "$log_file"
      done
    • Save the 13 test SQL queries from Appendix: SSB test SQL as q1.sql through q13.sql in the benchmark/query/ directory.

  2. Go to the benchmark directory and run the following command to start the test:

    sh benchmark.sh <database> 2 <host>
    • <database>: The name of the database.

    • 2: The number of rounds to run. The script uses the result from the final round.

    • <host>: The database host address.

Appendix: SSB test SQL

The following are the 13 standard SSB test SQL queries.

  • Q1.1

    SELECT sum(lo_extendedprice * lo_discount) AS revenue
    FROM lineorder_flat
    WHERE lo_orderdate >= '1993-01-01' and lo_orderdate <= '1993-12-31' AND lo_discount BETWEEN 1 AND 3 AND lo_quantity < 25;
  • Q1.2

    SELECT sum(lo_extendedprice * lo_discount) AS revenue FROM lineorder_flat
    WHERE lo_orderdate >= '1994-01-01' and lo_orderdate <= '1994-01-31' AND lo_discount BETWEEN 4 AND 6 AND lo_quantity BETWEEN 26 AND 35;
  • Q1.3

    SELECT sum(lo_extendedprice * lo_discount) AS revenue
    FROM lineorder_flat
    WHERE extract(week from lo_orderdate) = 6 AND lo_orderdate >= '1994-01-01' and lo_orderdate <= '1994-12-31' AND lo_discount BETWEEN 5 AND 7 AND lo_quantity BETWEEN 26 AND 35;
  • Q2.1

    SELECT sum(lo_revenue), extract(year from lo_orderdate) AS year, p_brand FROM lineorder_flat
    WHERE p_category = 'MFGR#12' AND s_region = 'AMERICA'
    GROUP BY year, p_brand
    ORDER BY year, p_brand
    LIMIT 100;
  • Q2.2

    SELECT sum(lo_revenue), extract(year from lo_orderdate) AS year, p_brand FROM lineorder_flat
    WHERE p_brand >= 'MFGR#2221' AND p_brand <= 'MFGR#2228' AND s_region = 'ASIA'
    GROUP BY year, p_brand
    ORDER BY year, p_brand
    LIMIT 100;
  • Q2.3

    SELECT sum(lo_revenue), extract(year from lo_orderdate) AS year, p_brand FROM lineorder_flat
    WHERE p_brand = 'MFGR#2239' AND s_region = 'EUROPE'
    GROUP BY year, p_brand
    ORDER BY year, p_brand
    LIMIT 100;
  • Q3.1

    SELECT c_nation, s_nation, extract(year from lo_orderdate) AS year, sum(lo_revenue) AS revenue FROM lineorder_flat
    WHERE c_region = 'ASIA' AND s_region = 'ASIA' AND lo_orderdate >= '1992-01-01' AND lo_orderdate <= '1997-12-31'
    GROUP BY c_nation, s_nation, year
    ORDER BY year ASC, revenue DESC
    LIMIT 100;
  • Q3.2

    SELECT c_city, s_city, extract(year from lo_orderdate) AS year, sum(lo_revenue) AS revenue
    FROM lineorder_flat
    WHERE c_nation = 'UNITED STATES' AND s_nation = 'UNITED STATES' AND lo_orderdate >= '1992-01-01' AND lo_orderdate <= '1997-12-31'
    GROUP BY c_city, s_city, year
    ORDER BY year ASC, revenue DESC
    LIMIT 100;
  • Q3.3

    SELECT c_city, s_city, extract(year from lo_orderdate) AS year, sum(lo_revenue) AS revenue
    FROM lineorder_flat
    WHERE c_city in ( 'UNITED KI1' ,'UNITED KI5') AND s_city in ( 'UNITED KI1' ,'UNITED KI5') AND lo_orderdate >= '1992-01-01' AND lo_orderdate <= '1997-12-31'
    GROUP BY c_city, s_city, year
    ORDER BY year ASC, revenue DESC
    LIMIT 100;
  • Q3.4

    SELECT c_city, s_city, extract(year from lo_orderdate) AS year, sum(lo_revenue) AS revenue
    FROM lineorder_flat
    WHERE c_city in ('UNITED KI1', 'UNITED KI5') AND s_city in ( 'UNITED KI1', 'UNITED KI5') AND lo_orderdate >= '1997-12-01' AND lo_orderdate <= '1997-12-31'
    GROUP BY c_city, s_city, year
    ORDER BY year ASC, revenue DESC
    LIMIT 100;
  • Q4.1

    SELECT EXTRACT(YEAR FROM lo_orderdate) AS YEAR, c_nation, SUM(lo_revenue - lo_supplycost) AS profit
    FROM lineorder_flat
    WHERE c_region = 'AMERICA' AND s_region = 'AMERICA' AND p_mfgr IN ('MFGR#1', 'MFGR#2')
    GROUP BY YEAR, c_nation
    ORDER BY YEAR ASC,c_nation ASC LIMIT 100;
  • Q4.2

    SELECT extract(year from lo_orderdate) AS year, s_nation, p_category, sum(lo_revenue - lo_supplycost) AS profit
    FROM lineorder_flat
    WHERE c_region = 'AMERICA' AND s_region = 'AMERICA' AND lo_orderdate >= '1997-01-01' and lo_orderdate <= '1998-12-31' AND p_mfgr in ( 'MFGR#1' , 'MFGR#2')
    GROUP BY year, s_nation, p_category
    ORDER BY year ASC, s_nation ASC, p_category ASC
    LIMIT 100;
  • Q4.3

    SELECT extract(year from lo_orderdate) AS year, s_city, p_brand, sum(lo_revenue - lo_supplycost) AS profit
    FROM lineorder_flat
    WHERE s_nation = 'UNITED STATES' AND lo_orderdate >= '1997-01-01' and lo_orderdate <= '1998-12-31' AND p_category = 'MFGR#14'
    GROUP BY year, s_city, p_brand
    ORDER BY year ASC, s_city ASC, p_brand ASC
    LIMIT 100;