← Status board  /  Phase 3

Phase 3 — Compose, DDL and the partition test The modelling decisions that decide the answer before any query runs: which key, which partition column, how many buckets, which compression — and the same fourteen columns modelled twice, once columnar and once as a row store with a clustered primary key.

Status complete StarRocks 3.5.21 · DUPLICATE KEY Partitions 25 · 100 tablets MySQL 8.0.46 · PK(id) + FULLTEXT Next Phase 4 · Load

1 Summary

Two tables with the same fourteen columns, modelled to each engine's strengths and to neither engine's convenience. The StarRocks side is append-only and partitioned by year; the MySQL side is a row store with a clustered primary key, two secondary indexes and one FULLTEXT index. Every non-obvious choice in the DDL carries its justification and the alternative that was discarded.

Columns
14
identical on both engines
Partitions
25
unknown · 2004–2026 · future
Tablets
100
25 partitions × 4 buckets
Healthy in
40 s
DDL applied clean on first run

2 The compose file

One file defines the whole lab: images pinned by digest, both services capped, healthchecks on both, and the MySQL flags that make the comparison honest.

SettingValueWhy
namesecop-labA fixed project name so container and volume names are predictable in scripts.
mem_limit / cpus4g / 4.0 eachSymmetric ceiling; neither engine gets headroom the other lacks.
innodb-buffer-pool-size1GDefault would be 128 MB, which turns every scan into a disk read and manufactures a loss.
local-infile1Required by LOAD DATA LOCAL INFILE; without it the load fails on the first row.
max-allowed-packet256MThe widest text column in the export is large enough to break the 64 MB default.
skip-log-binonThe lab never replicates; binary logging would add write overhead that belongs to neither engine's query path.
Healthchecksboth servicesup -d returning is not the same as the FE accepting SQL; the benchmark waits for healthy.

3 The StarRocks table model

CREATE TABLE secop.contratos (
  anio         INT           NOT NULL,
  id           VARCHAR(120)  NOT NULL,
  fuente       CHAR(2)       NOT NULL,
  entidad      VARCHAR(600),
  nit_entidad  VARCHAR(40),
  codigo_entidad VARCHAR(40),
  contratista  VARCHAR(600),
  representante VARCHAR(300),
  objeto       VARCHAR(2000),
  detalle      STRING,
  fecha_firma  DATE,
  valor        DOUBLE,
  departamento VARCHAR(200),
  municipio    VARCHAR(200)
)
DUPLICATE KEY(anio, id)
PARTITION BY RANGE(anio) ( ... 25 partitions ... )
DISTRIBUTED BY HASH(id) BUCKETS 4
PROPERTIES ("replication_num" = "1", "compression" = "ZSTD");
ChoiceAlternative discardedReason
DUPLICATE KEYPRIMARY KEY / UNIQUE KEYThe table is append-only and carries no updates. A primary-key model pays merge cost on every load and every compaction to protect a uniqueness the data already has. Duplicate key keeps the load a pure append, which is also what makes the Stream Load time meaningful.
BUCKETS 41, 8, or autoOne BE, 0.69 GB, 25 partitions: one bucket per partition would create 25 tiny tablets with fixed overhead each. Four keeps 100 tablets of a few MB and gives the BE something to schedule in parallel without fragmenting.
ZSTDLZ4LZ4 decompresses faster; ZSTD stores less. With the data already in memory the decompression cost is amortised across five runs, so the smaller footprint wins — it leaves more room inside the 4 GiB cap for the aggregation state of Q1.
replication_num = 13 (the default)Mandatory with a single BE: the default of 3 makes table creation fail. It is a consequence of the lab shape, not a recommendation, and the DDL says so in a comment.
14 physical columnsAll 85 + 96The queries touch these fourteen. Carrying the other 167 would multiply the load time and the storage to support queries nobody runs.

4 Partitions, and the year that does not exist

Year is the only column with a natural, business-meaningful range, and it is the filter Q1 and Q4 use. It also has a hole: about 1.58 million source rows have no usable date, so the derived year is 0 — 120,778 of them inside the subset.

PartitionRangeContent
p_unknown< 2004Every row with anio = 0 (120,778 in the subset) plus the handful of pre-2004 records. An explicit home for "no date" instead of letting those rows fall outside every range and fail the load.
p2004 … p2026one per year23 partitions, each holding a single year.
p_future< 2100A landing zone so that a re-export with a later year cannot fail the load at 3 a.m.

Why an integer year and not expression partitioning

date_trunc('year', ts) was tested on 3.5.21 and does work — the test created p2023 and p2024 on demand from a timestamp column. It was still rejected: expression partitioning needs a date column that is present, and 1.58 million rows have no date at all. An integer year can carry an explicit 0 = unknown; a truncated timestamp cannot, and those rows would silently land in no partition.

5 Two errors the DDL produced, and what they taught

1 · Unquoted range bounds

PARTITION p2004 VALUES LESS THAN (2004)
  -> ERROR 1064 (42000)

PARTITION p2004 VALUES LESS THAN ("2004")
  -> 25 partitions created

On 3.5.21 the bounds are parsed as strings even for an INT column. The message points at the statement, not the literal, so the first reading suggested a syntax error in the partition clause rather than a type mismatch inside it.

2 · Pruning cannot be shown on an empty table

EXPLAIN SELECT COUNT(*) FROM secop.contratos
  WHERE anio = 2024;
  -> EMPTYSET

The optimizer short-circuits when there is no data, so partitions=1/25 could not be demonstrated here. Rather than assert it from the documentation, verification was deferred to Phase 4 and recorded as an open item — where it was then confirmed with 1.3 M rows loaded.

6 The MySQL twin

The same fourteen columns, modelled as a row store. This is where MySQL's advantages come from, so the DDL gives them deliberately: a clustered primary key for the point lookup, a secondary index for the entity filter and an inverted FULLTEXT index for the native text search.

ObjectDefinitionWhat it is for
Column set14, same names and orderIdentical SELECT lists on both engines; no column exists on one side only.
Primary keyPRIMARY KEY (id)Clustered: the row lives in the index leaf. Q3 (anio + id) resolves in 3–4 page reads instead of a partition scan.
Secondary indexKEY idx_anio (anio)Supports the year filter in Q1 and Q4.
Secondary indexKEY idx_entidad (entidad(64))Prefix index: full-width index on a 600-char column would double the table size for a filter that mostly matches a prefix.
Full-textFULLTEXT KEY ft_detalle (detalle)The native option for Q2b. It is what makes Q2b a genuine win for MySQL rather than a curiosity.
Collationutf8mb4_0900_ai_ciSame as the production source, so the reference counts from Phase 0 remain comparable — and, as Phase 4 discovered, the reason a literal LIKE means two different things on the two engines.
Deliberate asymmetry

StarRocks has no secondary indexes here and MySQL does. That is not an oversight: the experiment asks what each engine does with its own strengths, not what happens when you disable them. The asymmetry is the subject of the benchmark, and each query states which side it favours.

7 The key-order consequence for Q3

StarRocks requires the partition column to lead the sort key, so anio must come before id in DUPLICATE KEY(anio, id). That changes the shape of the point lookup:

-- what the plan requires
WHERE anio = ? AND id = ?

-- what would have been flattering
WHERE id = ?

The second form would scan all 25 partitions and lose to MySQL by a wide margin — an easy headline and a dishonest one. A lookup that knows the year and the contract reference is what someone actually does with this table, so that is the query Q3 runs.

What Q3 measures

Not "can StarRocks find a row by id" — it cannot, by design of the sort key — but "what does a realistic reference lookup cost when the engine has no point index". That is a genuine loss and it belongs in the report next to the wins.

8 Gate

Gate met

docker compose up -d left both engines healthy in 40 s; SELECT 1 answers on 9030; StarRocks reports 3.5.21-85fccf8 with BE 10001 alive; MySQL reports 8.0.46 with a 1 GB buffer pool; the DDL applied clean and created 25 partitions, 100 tablets. Pruning was explicitly left open at this point and verified in Phase 4 at partitions=1/25.

9 Evidence