Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions opengauss-column/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
This is the `opengauss` entry with one change: `hits` is created
`WITH (ORIENTATION = COLUMN)`, so it lives in openGauss's column store and is
read by its vectorized executor instead of the row-at-a-time one. openGauss
documents the column store as the storage for "data warehouse services with a
large amount of aggregation computing", which is what ClickBench is.

Read `../opengauss/README.md` first: installation from the openEuler tarball,
the two bridged sonames, the `omm` user, `DBCOMPATIBILITY = 'PG'`, the way
files reach `gsql` on stdin, and the `query_dop` / `max_connections`
relationship are all identical here and are only described there.

To run the benchmark:

```
./benchmark.sh
```

## What differs from the row-store entry

- `create.sql` ends in `) WITH (ORIENTATION = COLUMN);`. openGauss accepts
every type the portable ClickBench schema uses in a column-store table, so
the schema is otherwise byte-for-byte the `postgresql` one. Compression is
left at the column store's default of `low`; `middle` and `high` exist and
would trade CPU for space.
- Nothing else. `install` is byte-for-byte the row-store entry's, including
`shared_buffers`: `cstore_buffers`, the CU cache the column store reads
through, is deliberately left at its default, because the driver restarts
the server and drops the page cache before every query, so a large CU cache
is never warm when it matters. An earlier revision of this entry gave it a
quarter of RAM and the c6a.4xlarge run spent about 30 minutes in each cold
cycle -- 18 queries in ten hours, against 156 seconds of actual query time.
- `./load` finishes with `ANALYZE` rather than `VACUUM ANALYZE`: there are no
heap pages to freeze and no visibility map to build.

## What the column store is worth

Loaded with the same 99,997,497 rows through the same scripts, the column
store takes 16 GB for the table and 31.3 GB for the whole data directory,
against 86.6 GB for the row store, and it loads in a little over half the
time.

Per query it is not uniformly better, which is the interesting part. It is
two to three orders of magnitude faster on the selective tail of the workload
— Q37 to Q43, which filter on `CounterID` and an `EventDate` range, drop from
229-303 s each to between 0.16 s and 1.8 s, because those queries read five or
six of the 105 columns where the row store has to walk every one of them. Q1
and Q20 finish in 65 ms.

It is *slower* than the row engine on `COUNT(DISTINCT ...)`. The scan is not
the problem: on a 1% slice, `SELECT COUNT(DISTINCT UserID)` spends 6 ms in
`CStore Scan` and 1.27 s in `Vector Aggregate`, where the row plan does the
whole thing in 0.38 s. Eight of the 43 queries use `COUNT(DISTINCT ...)` and
all eight pay this.

## A constant in the GROUP BY costs an order of magnitude

Q34 and Q35 differ only in that Q35 adds a constant to the grouping list:

```sql
SELECT URL, COUNT(*) AS c FROM hits GROUP BY URL ORDER BY c DESC LIMIT 10; -- Q34
SELECT 1, URL, COUNT(*) AS c FROM hits GROUP BY 1, URL ORDER BY c DESC LIMIT 10; -- Q35
```

The plans are structurally identical — `CStore Scan`, `Vector Sonic Hash
Aggregate`, `Vector Streaming(LOCAL REDISTRIBUTE)`, a second aggregate, sort,
limit — and differ in exactly one line, which `EXPLAIN VERBOSE` shows on the
redistribution:

```
Q34: Distribute Key: url
Q35: Distribute Key: (1)
```

The planner keys the redistribution on the leading grouping column, and for
Q35 that column is the constant, so every row hashes to the same worker and
the other 47 have nothing to do. Measured back to back on the full 100M rows
with `query_dop = 48`:

| query | `query_dop = 48` | `query_dop = 1` |
| --- | --- | --- |
| Q34, `GROUP BY URL` | 50.9 s | 456.1 s |
| Q35, `GROUP BY 1, URL` | 636.6 s | 397.6 s |
| Q35 rewritten, `GROUP BY URL, 2` | 22.5 s | |

Parallelism is worth 9x to Q34 and nothing at all to Q35 — at `query_dop = 48`
Q35 is in fact slower than at `query_dop = 1`, since it pays for the
redistribution and gets no distribution out of it. Moving the constant to the
end of the grouping list restores `Distribute Key: url` and, with it, the
runtime.

The query is left exactly as ClickBench specifies it. This is worth reporting
to the openGauss community; it has not been filed yet.

## An aggregate `FILTER` clause takes the instance down

Not a ClickBench query — none of the 43 uses `FILTER` — but found while
measuring this dataset, and worth knowing about before anyone else spends an
evening on it. On a column-store table, an aggregate with a `FILTER` clause
kills the whole `gaussdb` instance, silently: no log entry, no core, every
session gets `connection to server was lost`, and the next start does redo
recovery. 1000 rows are enough:

```sql
CREATE TABLE t_col (a int, b int) WITH (ORIENTATION = COLUMN);
INSERT INTO t_col SELECT i, i % 7 FROM generate_series(1, 1000) i;
SELECT count(*) FILTER (WHERE b = 1) FROM t_col; -- instance gone
```

The same statement against a row-store table answers normally, so it is the
vectorized path. Also unfiled.

## Verification

These scripts were run end to end on the full dataset: `./load` gets exactly
99,997,497 rows in and all 43 queries return a result, none erroring or timing
out. Every one of the 43 was then compared against the row-store entry's
answers for the same 100M rows — the two execution engines agree on 34 of them
exactly, and the 9 that differ are all queries where a `LIMIT` cuts through a
run of tied sort keys (Q18 has no `ORDER BY` at all). Correctness against
`clickhouse-local` was checked query by query on a 1% slice, as described in
`../opengauss/README.md`.

No results yet — those need runs on the benchmark's own EC2 machines.
3 changes: 3 additions & 0 deletions opengauss-column/benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
export BENCH_DOWNLOAD_SCRIPT="download-hits-tsv"
exec ../lib/benchmark-common.sh
9 changes: 9 additions & 0 deletions opengauss-column/check
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

OG_ROOT=${OG_ROOT:-/opt/opengauss}
OG_USER=${OG_USER:-omm}

# gsql exits 0 even when it cannot connect, so match on the output instead.
out=$(sudo -u "$OG_USER" "$OG_ROOT/run" gsql -d postgres -t -A -c 'SELECT 1' 2>&1)
[ "$out" = "1" ]
108 changes: 108 additions & 0 deletions opengauss-column/create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
CREATE TABLE hits
(
WatchID BIGINT NOT NULL,
JavaEnable SMALLINT NOT NULL,
Title TEXT NOT NULL,
GoodEvent SMALLINT NOT NULL,
EventTime TIMESTAMP NOT NULL,
EventDate Date NOT NULL,
CounterID INTEGER NOT NULL,
ClientIP INTEGER NOT NULL,
RegionID INTEGER NOT NULL,
UserID BIGINT NOT NULL,
CounterClass SMALLINT NOT NULL,
OS SMALLINT NOT NULL,
UserAgent SMALLINT NOT NULL,
URL TEXT NOT NULL,
Referer TEXT NOT NULL,
IsRefresh SMALLINT NOT NULL,
RefererCategoryID SMALLINT NOT NULL,
RefererRegionID INTEGER NOT NULL,
URLCategoryID SMALLINT NOT NULL,
URLRegionID INTEGER NOT NULL,
ResolutionWidth SMALLINT NOT NULL,
ResolutionHeight SMALLINT NOT NULL,
ResolutionDepth SMALLINT NOT NULL,
FlashMajor SMALLINT NOT NULL,
FlashMinor SMALLINT NOT NULL,
FlashMinor2 TEXT NOT NULL,
NetMajor SMALLINT NOT NULL,
NetMinor SMALLINT NOT NULL,
UserAgentMajor SMALLINT NOT NULL,
UserAgentMinor VARCHAR(255) NOT NULL,
CookieEnable SMALLINT NOT NULL,
JavascriptEnable SMALLINT NOT NULL,
IsMobile SMALLINT NOT NULL,
MobilePhone SMALLINT NOT NULL,
MobilePhoneModel TEXT NOT NULL,
Params TEXT NOT NULL,
IPNetworkID INTEGER NOT NULL,
TraficSourceID SMALLINT NOT NULL,
SearchEngineID SMALLINT NOT NULL,
SearchPhrase TEXT NOT NULL,
AdvEngineID SMALLINT NOT NULL,
IsArtifical SMALLINT NOT NULL,
WindowClientWidth SMALLINT NOT NULL,
WindowClientHeight SMALLINT NOT NULL,
ClientTimeZone SMALLINT NOT NULL,
ClientEventTime TIMESTAMP NOT NULL,
SilverlightVersion1 SMALLINT NOT NULL,
SilverlightVersion2 SMALLINT NOT NULL,
SilverlightVersion3 INTEGER NOT NULL,
SilverlightVersion4 SMALLINT NOT NULL,
PageCharset TEXT NOT NULL,
CodeVersion INTEGER NOT NULL,
IsLink SMALLINT NOT NULL,
IsDownload SMALLINT NOT NULL,
IsNotBounce SMALLINT NOT NULL,
FUniqID BIGINT NOT NULL,
OriginalURL TEXT NOT NULL,
HID INTEGER NOT NULL,
IsOldCounter SMALLINT NOT NULL,
IsEvent SMALLINT NOT NULL,
IsParameter SMALLINT NOT NULL,
DontCountHits SMALLINT NOT NULL,
WithHash SMALLINT NOT NULL,
HitColor CHAR NOT NULL,
LocalEventTime TIMESTAMP NOT NULL,
Age SMALLINT NOT NULL,
Sex SMALLINT NOT NULL,
Income SMALLINT NOT NULL,
Interests SMALLINT NOT NULL,
Robotness SMALLINT NOT NULL,
RemoteIP INTEGER NOT NULL,
WindowName INTEGER NOT NULL,
OpenerName INTEGER NOT NULL,
HistoryLength SMALLINT NOT NULL,
BrowserLanguage TEXT NOT NULL,
BrowserCountry TEXT NOT NULL,
SocialNetwork TEXT NOT NULL,
SocialAction TEXT NOT NULL,
HTTPError SMALLINT NOT NULL,
SendTiming INTEGER NOT NULL,
DNSTiming INTEGER NOT NULL,
ConnectTiming INTEGER NOT NULL,
ResponseStartTiming INTEGER NOT NULL,
ResponseEndTiming INTEGER NOT NULL,
FetchTiming INTEGER NOT NULL,
SocialSourceNetworkID SMALLINT NOT NULL,
SocialSourcePage TEXT NOT NULL,
ParamPrice BIGINT NOT NULL,
ParamOrderID TEXT NOT NULL,
ParamCurrency TEXT NOT NULL,
ParamCurrencyID SMALLINT NOT NULL,
OpenstatServiceName TEXT NOT NULL,
OpenstatCampaignID TEXT NOT NULL,
OpenstatAdID TEXT NOT NULL,
OpenstatSourceID TEXT NOT NULL,
UTMSource TEXT NOT NULL,
UTMMedium TEXT NOT NULL,
UTMCampaign TEXT NOT NULL,
UTMContent TEXT NOT NULL,
UTMTerm TEXT NOT NULL,
FromTag TEXT NOT NULL,
HasGCLID SMALLINT NOT NULL,
RefererHash BIGINT NOT NULL,
URLHash BIGINT NOT NULL,
CLID INTEGER NOT NULL
) WITH (ORIENTATION = COLUMN);
6 changes: 6 additions & 0 deletions opengauss-column/data-size
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -eu

OG_ROOT=${OG_ROOT:-/opt/opengauss}

sudo du -bcs "$OG_ROOT/data" | grep total | awk '{print $1}'
139 changes: 139 additions & 0 deletions opengauss-column/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash
# openGauss publishes binaries for openEuler and CentOS only, so there is no
# apt repository to add. The openEuler 20.03 server tarball is glibc 2.28 and
# runs unmodified on Ubuntu once two sonames are bridged: libaio.so.1 (Ubuntu
# renamed it libaio.so.1t64 in the 64-bit time_t transition, an ABI no-op on
# 64-bit) and libreadline.so.7 (Ubuntu ships readline 8, which gsql only uses
# for line editing). Both symlinks live in a private directory that is added
# to LD_LIBRARY_PATH, so nothing outside $OG_ROOT is touched.
set -eu

OG_VERSION=${OG_VERSION:-6.0.5}
OG_ROOT=${OG_ROOT:-/opt/opengauss}
OG_USER=${OG_USER:-omm}
OG_PORT=${OG_PORT:-5432}

# Nothing to do if a previous run already initialized the cluster.
if [ -f "$OG_ROOT/data/postgresql.conf" ]; then
echo "opengauss: cluster already initialized in $OG_ROOT/data" >&2
exit 0
fi

case "$(uname -m)" in
x86_64) og_arch=x86; og_suffix=x86_64 ;;
aarch64) og_arch=arm; og_suffix=aarch64 ;;
*) echo "opengauss: unsupported architecture $(uname -m)" >&2; exit 1 ;;
esac
og_file="openGauss-Server-${OG_VERSION}-openEuler20.03-${og_suffix}.tar.bz2"
og_url="https://opengauss.obs.cn-south-1.myhuaweicloud.com/${OG_VERSION}/openEuler20.03/${og_arch}/${og_file}"

sudo apt-get update -y
sudo apt-get install -y wget bzip2 libreadline8 libncurses6 libncursesw6 libtinfo6 libcrypt1
# libaio1t64 on Ubuntu 24.04+, libaio1 on older releases.
sudo apt-get install -y libaio1t64 || sudo apt-get install -y libaio1

# A dedicated OS user: openGauss refuses to start as root.
if ! id "$OG_USER" >/dev/null 2>&1; then
sudo useradd -m -s /bin/bash "$OG_USER"
fi

sudo mkdir -p "$OG_ROOT/app" "$OG_ROOT/data" "$OG_ROOT/log" "$OG_ROOT/compat" "$OG_ROOT/tmp"

wget --continue --progress=dot:giga -O "/tmp/$og_file" "$og_url"
sudo tar xjf "/tmp/$og_file" -C "$OG_ROOT/app"
rm -f "/tmp/$og_file"

libdir="/usr/lib/$(uname -m)-linux-gnu"
sudo ln -sf "$(ls "$libdir"/libaio.so.1* | head -n1)" "$OG_ROOT/compat/libaio.so.1"
sudo ln -sf "$(ls "$libdir"/libreadline.so.8* | head -n1)" "$OG_ROOT/compat/libreadline.so.7"

# Every other script runs commands through $OG_ROOT/run, which sources this
# environment and drops the caller into the openGauss toolchain.
sudo tee "$OG_ROOT/env.sh" >/dev/null <<EOF
export GAUSSHOME=$OG_ROOT/app
export GAUSSLOG=$OG_ROOT/log
export LD_LIBRARY_PATH=$OG_ROOT/app/lib:$OG_ROOT/compat
export PATH=$OG_ROOT/app/bin:\$PATH
export PGDATA=$OG_ROOT/data
export PGPORT=$OG_PORT
export PGHOST=$OG_ROOT/tmp
export TMPDIR=$OG_ROOT/tmp
# Bound each ./check probe: a server still replaying WAL accepts the
# connection and then sits on it, which would turn the driver's readiness
# loop into a multi-minute stall per cold cycle.
export PGCONNECT_TIMEOUT=5
EOF
sudo tee "$OG_ROOT/run" >/dev/null <<EOF
#!/bin/bash
# openGauss's installation guide asks for a nofile limit of 1000000, and it
# means it: the server derives max_safe_fds from whatever the shell had, so
# under the 1024 that cloud-init leaves in place a hash aggregation that
# spills dies with 'could not create temporary file ... Too many open files'.
ulimit -n 1000000 2>/dev/null || ulimit -n "\$(ulimit -Hn)" 2>/dev/null || true
source $OG_ROOT/env.sh
exec "\$@"
EOF
sudo chmod 755 "$OG_ROOT/run"
sudo chown -R "$OG_USER:$OG_USER" "$OG_ROOT"

# Initialize the cluster. -A trust keeps the benchmark scripts free of
# password handling; the instance only listens on a Unix socket anyway.
sudo -u "$OG_USER" "$OG_ROOT/run" gs_initdb -D "$OG_ROOT/data" \
--nodename=clickbench -w 'Clickbench@123' -E UTF8 --locale=C -A trust

memory_kb=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
threads=$(nproc)

# openGauss parallelizes a query only when query_dop is raised above its
# default of 1; without it a 16-core machine runs every scan on one core.
# Half the threads is the same share the postgresql entry hands to
# max_parallel_workers_per_gather, and 64 is the ceiling the GUC accepts.
query_dop=$((threads / 2))
[ "$query_dop" -lt 1 ] && query_dop=1
[ "$query_dop" -gt 64 ] && query_dop=64

# Every thread of a parallel plan takes a connection slot, so the driver's
# 10-connection throughput test needs roughly 10 x query_dop of them at
# once; with the default 200 it dies with "No free proc is available to
# create a new connection". 30 slots per unit of query_dop leaves room for
# the producer/consumer pairs a stream plan adds on top.
max_connections=$((query_dop * 30 + 200))

# openGauss caps the whole instance with max_process_memory (default 12 GB
# regardless of the machine): too small and big GROUP BYs fail with "memory
# is temporarily unavailable", too large and the OOM killer arrives first.
# 80% of RAM, floored at the 2 GB the GUC accepts as a minimum.
max_process_memory=$((memory_kb * 4 / 5))
[ "$max_process_memory" -lt 2097152 ] && max_process_memory=2097152

# Same 25%-of-RAM rule as the row-store entry. cstore_buffers, the CU cache
# the column store reads through, is deliberately left at its default: the
# driver restarts the server and drops the page cache before every query, so
# a large CU cache is never warm when it matters and only costs memory on the
# 32 GB machines.
shared_buffers=$((memory_kb / 4))
effective_cache_size=$((memory_kb - memory_kb / 4))

# An eighth of RAM for the post-load ANALYZE, but never more than 2 GB --
# t3a.small only has 2 GB in total.
maintenance_work_mem=$((memory_kb / 8))
[ "$maintenance_work_mem" -gt 2097152 ] && maintenance_work_mem=2097152

# 16 MB per segment; 2048 segments is the 32 GB the postgresql entry gives
# max_wal_size, which keeps checkpoints out of the middle of the load.
sudo -u "$OG_USER" tee -a "$OG_ROOT/data/postgresql.conf" >/dev/null <<EOF

# ClickBench
port = $OG_PORT
max_process_memory = ${max_process_memory}kB
shared_buffers = ${shared_buffers}kB
effective_cache_size = ${effective_cache_size}kB
work_mem = 64MB
max_files_per_process = 100000
query_dop = $query_dop
max_connections = $max_connections
maintenance_work_mem = ${maintenance_work_mem}kB
checkpoint_segments = 2048
unix_socket_directory = '$OG_ROOT/tmp'
log_directory = '$OG_ROOT/log'
EOF
Loading