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.
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.
| Setting | Value | Why |
|---|---|---|
name | secop-lab | A fixed project name so container and volume names are predictable in scripts. |
mem_limit / cpus | 4g / 4.0 each | Symmetric ceiling; neither engine gets headroom the other lacks. |
innodb-buffer-pool-size | 1G | Default would be 128 MB, which turns every scan into a disk read and manufactures a loss. |
local-infile | 1 | Required by LOAD DATA LOCAL INFILE; without it the load fails on the first row. |
max-allowed-packet | 256M | The widest text column in the export is large enough to break the 64 MB default. |
skip-log-bin | on | The lab never replicates; binary logging would add write overhead that belongs to neither engine's query path. |
| Healthchecks | both services | up -d returning is not the same as the FE accepting SQL; the benchmark waits for healthy. |
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");
| Choice | Alternative discarded | Reason |
|---|---|---|
DUPLICATE KEY | PRIMARY KEY / UNIQUE KEY | The 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 4 | 1, 8, or auto | One 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. |
ZSTD | LZ4 | LZ4 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 = 1 | 3 (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 columns | All 85 + 96 | The queries touch these fourteen. Carrying the other 167 would multiply the load time and the storage to support queries nobody runs. |
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.
| Partition | Range | Content |
|---|---|---|
p_unknown | < 2004 | Every 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 … p2026 | one per year | 23 partitions, each holding a single year. |
p_future | < 2100 | A landing zone so that a re-export with a later year cannot fail the load at 3 a.m. |
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.
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.
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.
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.
| Object | Definition | What it is for |
|---|---|---|
| Column set | 14, same names and order | Identical SELECT lists on both engines; no column exists on one side only. |
| Primary key | PRIMARY 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 index | KEY idx_anio (anio) | Supports the year filter in Q1 and Q4. |
| Secondary index | KEY 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-text | FULLTEXT KEY ft_detalle (detalle) | The native option for Q2b. It is what makes Q2b a genuine win for MySQL rather than a curiosity. |
| Collation | utf8mb4_0900_ai_ci | Same 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. |
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.
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.
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.
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.
ddl.sql — the StarRocks table with one comment per decision, plus the discarded alternative.sql/05_ddl_mysql.sql — the MySQL twin.sql/02_partition_test.sql — the date_trunc test that proved expression partitioning works and was still not the right choice.sql/06_f4_verification.out.txt §7 — the pruning proof, obtained once the table had rows.