# Phase 0 — Schema notes (measured)

Status: **closed — subset awaiting approval** · last update 2026-11-25 15:50 (America/Bogota)
Source: `secop_i_ii_integrado` @ 129.80.141.192 (`pidecerca-prod`)
Access: SSH `ubuntu@pidecerca-prod` → local MySQL socket as `root@localhost`, read-only queries only.

Everything below is measured. No value is copied from the brief unless it was reproduced here; where the brief and the server disagree, both numbers are shown and the disagreement is named.

---

## 1. Server profile

| Item | Measured |
|---|---|
| MySQL version | `8.0.46-0ubuntu0.24.04.5` (Linux, aarch64) |
| Host | `pidecerca-prod` |
| Port | 3306, bound to `127.0.0.1` only (not reachable from outside) |
| Charset / collation | `utf8mb4` / `utf8mb4_0900_ai_ci` (accent- and case-insensitive) |
| InnoDB buffer pool | **3.0 GB** |
| Databases | `information_schema`, `mysql`, `performance_schema`, `secop_i_ii_integrado`, `sys` |

The 3 GB buffer pool matters for reading the timings in §5: a 26.8 GB table cannot stay cached, so every full scan pays physical I/O.

## 2. Objects and physical size

| Object | Rows (`COUNT(*)`) | `.ibd` file | Notes |
|---|---|---|---|
| `secop_i_records` | **11,120,877** | **26.83 GB** | matches the brief exactly |
| `secop_ii_registros` | **5,887,396** | **16.27 GB** | matches the brief exactly |
| Schema total | 94 objects | **≈46.7 GiB** (file blocks) | brief said 93 tables |

Two discrepancies against the brief, both recorded rather than smoothed:

- **94 objects, not 93.** The extras are materialised views: `secop_global_municipio_contratista_mv` (1.38 GB) and `secop_global_municipio_representante_mv` (1.05 GB). They are derived data, not source rows.
- **File size ≠ payload size.** The brief's 21.89 / 13.97 GB are data payload; the `.ibd` files are 26.83 / 16.27 GB because each FULLTEXT index lives in its own `fts_*.ibd` file and is counted in the file listing. For the CSV export budget, payload is the relevant figure — indexes do not travel.

`information_schema.TABLES` in this schema is **unusable**: it reports 411,423 rows and 445 MB for the whole schema, against 17 M rows and ~47 GiB on disk. The tables were rebuilt this morning (08:15 and 10:03) and the statistics were never refreshed. Any step that would read `TABLE_ROWS` must use `COUNT(*)` instead — this extends to the DDL comments.

## 3. Column inventory

`secop_i_records`: **85 columns**. `secop_ii_registros`: **96 columns**. The seven columns named in the brief all exist; they are a subset, not the schema.

### Value columns — decision closed (was blocker B3)

The contract value is **numeric, not text**. No thousands separators to strip, no derived column needed.

| Table | Numeric value columns |
|---|---|
| `secop_i_records` | `Cuantia_Proceso`, `Cuantia_Contrato`, `Valor_Total_de_Adiciones`, `Valor_Contrato_con_Adiciones`, `Valor_Rubro` — all `double`; plus `Valor_Rubro` per budget line |
| `secop_ii_registros` | `valor_contrato`, `valor_pago_adelantado`, `valor_facturado`, `valor_pagado`, `valor_pendiente_pago`, `valor_amortizado`, `valor_pendiente_amortizacion`, `valor_pendiente_ejecucion`, `valor_facturado_total` — all `double` |

Consequence for Q1: `SUM(Cuantia_Contrato)` / `SUM(valor_contrato)` are computed identically by both engines. No cleaning logic, therefore no chance of biasing the comparison with engine-specific string handling.

Open sub-question: how many rows carry `NULL` or `0` in the chosen value column — being measured in the running diagnostic (see §6).

### Date columns — affects partitioning

| Table | Usable date | Type | Comment |
|---|---|---|---|
| `secop_ii_registros` | `fecha_firma` | **`date`** | clean; plus `fecha_inicio_contrato`, `fecha_fin_contrato` (`date`), and several `datetime` |
| `secop_i_records` | `Fecha_de_Firma_del_Contrato` | **`text`** | not a date type |
| `secop_i_records` | `Anno_Firma_del_Contrato` | `varchar(1024)` | year as a string; needs a cast to drive partitioning |

So year partitioning is native on SECOP II and requires a derived integer year on SECOP I. That derivation must happen identically in the export and in both loads, and it gets documented as part of the model — not hidden inside the query.

### Text columns that matter for Q2

`secop_i_records.Detalle_del_Objeto_a_Contratar` (`text`), `secop_ii_registros.objeto_contrato`, `descripcion_proceso`, `condiciones_entrega`, `descripcion_documentos_tipo` (all `text`). All five are covered by FULLTEXT indexes.

## 4. Indexes

`secop_i_records` — 4 FULLTEXT, exactly as the brief said:

| Index | Column |
|---|---|
| `ft_detalle_objeto_contratar` | `Detalle_del_Objeto_a_Contratar` |
| `ft_nom_raz_social_contratista` | `Nom_Raz_Social_Contratista` |
| `ft_nombre_entidad_secop1` | `Nombre_de_la_Entidad` |
| `ft_nombre_represen_legal` | `Nombre_del_Represen_Legal` |

Plus `PRIMARY (UID)`, five composite BTREE on the territory codes, and two BTREE on `Numero_de_Proceso` / `Numero_del_Contrato`.

`secop_ii_registros` — 7 FULLTEXT, also matching the brief:

| Index | Column |
|---|---|
| `ft_condiciones_entrega` | `condiciones_entrega` |
| `ft_descripcion_documentos_tipo` | `descripcion_documentos_tipo` |
| `ft_descripcion_proceso` | `descripcion_proceso` |
| `ft_nombre_entidad` | `nombre_entidad` |
| `ft_nombre_representante` | `nombre_representante_legal` |
| `ft_objeto_contrato` | `objeto_contrato` |
| `ft_proveedor_adjudicado` | `proveedor_adjudicado` |

Plus `PRIMARY (id_contrato)` — a real clustered-key point lookup for Q3 — and eight composite BTREE, including `idx_secop2_entidad_periodo_nit_fecha_firma (nit_entidad_n, fecha_firma)`, which is the one that can serve a filtered aggregation on SECOP II.

Neither table is partitioned (`PARTITION_COUNT = 1`). There is therefore no pruning to inherit: partitioning in the lab is our own design decision, and its benefit must be demonstrated, not assumed.

## 5. Reference counts — validation result

| Probe | Measured | Brief | Δ | Elapsed | Effective rate |
|---|---|---|---|---|---|
| `bogota` in `Nombre_de_la_Entidad` | **667,388** | 667,388 | 0 | 219.2 s | 122 MB/s |
| `bogota` in `nombre_entidad` (SECOP II) | **70,941** | 70,941 | 0 | 187.6 s | 87 MB/s |
| `computadores` in `Detalle_del_Objeto_a_Contratar` | **23,883** | 23,372 | **+511 (+2.19 %)** | 223.8 s | 120 MB/s |

Two of three anchors reproduce exactly. The third differed by 2.19 %, well outside the ±1 % tolerance, so it was investigated instead of accepted. **It is resolved: all three operators are correct, and they answer three different questions.**

| Operator | Count | What it means |
|---|---|---|
| `MATCH … AGAINST('computadores' IN BOOLEAN MODE)` | **23,372** | FULLTEXT word match — **this is the brief's number** |
| `LIKE '%computadores%'` (`utf8mb4_0900_ai_ci`) | **23,883** | substring match, case- and accent-insensitive |
| `LIKE BINARY '%computadores%'` | **5,358** | substring match, byte-exact (lower-case only) |

Root cause: FULLTEXT indexes *tokens*. A word glued to punctuation or to another word is not indexed as the separate term `computadores`, so `MATCH` misses it while `LIKE` finds the substring. The +511 gap is exactly that population. The 5,358 confirms a second fact about the corpus: the term appears capitalised ("Computadores") in the large majority of rows — 78 % of matches — which is why a case-sensitive byte comparison collapses the count by 4.5×.

Consequence, recorded for the report: the same business question — "how many contracts mention computers" — returns 23,372, 23,883 or 5,358 depending on the operator. This is the concrete justification for keeping Q2a (`LIKE`, identical on both engines) and Q2b (native FULLTEXT) in separate tables.

### Scan cost, measured

These three scans are also the first throughput measurement on this server: **≈120 MB/s** on SECOP I with a 3 GB buffer pool, **≈87 MB/s** on SECOP II. That is the floor StarRocks has to beat on the same hardware class, and the reason the subset must be small enough to stay in memory.

## 6. Year distribution (measured)

`secop_i_records`, by `LEFT(Anno_Firma_del_Contrato,4)` — 224 s, full scan:

| Year | Rows | Year | Rows |
|---|---|---|---|
| 2017 | 1,177,661 | 2014 | 776,302 |
| *(blank/NULL)* | **1,152,071** | 2013 | 607,337 |
| 2019 | 1,142,037 | 2012 | 455,450 |
| 2016 | 1,070,124 | 2022 | 433,313 |
| 2018 | 1,050,188 | 2011 | 198,179 |
| 2020 | 918,805 | 2004–2010 | 333,985 |
| 2015 | 907,054 | < 2004 | 199 |
| 2021 | 896,136 | | |

`secop_ii_registros`, by `YEAR(fecha_firma)` — 5 s (served from index):

| Year | Rows | Year | Rows |
|---|---|---|---|
| 2025 | 1,041,083 | *(NULL)* | **423,466** |
| 2024 | 935,116 | 2020 | 357,109 |
| 2023 | 841,348 | 2018 | 142,909 |
| 2022 | 709,916 | 2019 | 142,556 |
| 2026 | 708,952 | 2017 | 22,253 |
| 2021 | 561,336 | 2015–2016 | 1,352 |

Two consequences: **10.4 % of SECOP I has no year at all** (the field is free text), and SECOP II carries 423,466 rows without `fecha_firma`. Any year-partitioned model needs an explicit "unknown" partition, or those rows silently vanish from every date-filtered query.

## 7. Value column quality

`Cuantia_Contrato` on SECOP I, one full scan (267 s):

| Metric | Value |
|---|---|
| Rows | 11,120,877 |
| `NULL` | **0** |
| `0` (zero) | **1,216,698** (10.9 %) |
| Maximum | **364,000,000,000,000** |

The maximum is not a contract value; it is a data-quality outlier (three orders of magnitude beyond any plausible COP figure). It matters for Q1: a single such row can dominate a `SUM`. Both engines read the same row, so the comparison stays fair, but the report must state that the aggregate is outlier-driven — otherwise the winner of Q1 looks like it won on volume rather than on speed.

## 8. Subset decision — proposal for approval

**Recommendation: Strategy B, deterministic modulo, `k = 13` (7.69 %).**

| Metric | Expected in subset | Threshold | Margin |
|---|---|---|---|
| `secop_i_records` rows | 855,452 | — | — |
| `secop_ii_registros` rows | 452,877 | — | — |
| Total rows | **1,308,329** | ≥ 1.2 M | +9 % |
| CSV payload (est.) | **≈ 2.7 GB** | ≤ 3 GB | −10 % |
| `bogota` SECOP I | ≈ 51,338 | ≥ 50,000 | +2.7 % |
| `bogota` SECOP II | ≈ 5,457 | ≥ 5,000 | +9 % |
| `computadores` (LIKE) | ≈ 1,837 | ≥ 1,500 | +22 % |

Predicate: `CRC32(UID) % 13 = 0` on SECOP I, `CRC32(id_contrato) % 13 = 0` on SECOP II. Deterministic, parallelisable, no `ORDER BY`, reproducible byte-for-byte from the same `k`.

**Why not year slicing (Strategy A).** The data rules it out at 4 GB. A single recent SECOP II year is already 935 k–1.04 M rows (≈2.2–2.5 GB), and 2023 alone is 841 k (≈2.0 GB); adding any meaningful SECOP I slice pushes the export past the 3 GB ceiling. Half-year windows would fit, but they add within-year seasonality, and on SECOP I the date is free text — a range filter there is not trustworthy. Year windows are too coarse for this corpus.

**Consequence to accept explicitly.** The sample is uniform, not date-based, so the year partitions in the DDL are a production modelling choice (how such a table would really be partitioned), and pruning is demonstrated with a year-filtered query over the sample. The partition key does not select the sample.

**What still has to be true after export:** the three counts are recomputed on the subset and compared against the expected values above at ±1 %; divergence beyond that means the modulo predicate is not behaving as assumed.

## 9. Still open

| # | Item | Impact |
|---|---|---|
| 1 | `SUB_PART` of BTREE indexes on `text` columns | Low — affects `SHOW CREATE TABLE` fidelity only |
| 2 | 94 vs 93 objects: confirm the two `*_mv` are the only extras | Low |
| 3 | Approval of the subset table above | **Blocking Phase 4** |
| 4 | StarRocks version + digest | Blocking Phase 1 compose |

## 10. What Phase 0 closed

- **B3 (value column)** — closed: `double`, no separators, but 10.9 % zeros and one absurd outlier recorded.
- **Partitioning design** — native on SECOP II (`fecha_firma`), derived on SECOP I (`Anno_Firma_del_Contrato` → integer year), plus an "unknown" partition on both.
- **Reference counts** — all three confirmed, the third under FULLTEXT semantics.
- **Subset sizing** — payload-based, `k = 13`, ≈2.7 GB, all validation thresholds met.
- **Throughput baseline** — ≈120 MB/s SECOP I, ≈87 MB/s SECOP II on 3 GB buffer pool. That is the bar StarRocks must clear.
