Skip to content

Consolidate special case regexp_match logic#21486

Open
alamb wants to merge 1 commit intoapache:mainfrom
alamb:alamb/test_coverage
Open

Consolidate special case regexp_match logic#21486
alamb wants to merge 1 commit intoapache:mainfrom
alamb:alamb/test_coverage

Conversation

@alamb
Copy link
Copy Markdown
Contributor

@alamb alamb commented Apr 8, 2026

Which issue does this PR close?

Rationale for this change

#21379 adds a specific optimization, but it had some non trivial code duplication

I wanted to reduce the duplication and also make the code easier to read(in my opinion)

What changes are included in this PR?

Move the special RegExp logic into its own struct, and add copious comments

Are these changes tested?

By existing tests, and the additional tests added in

Are there any user-facing changes?

No this is internal changes only

I ran benchmarks and see no change in performance (as expected)

@alamb alamb marked this pull request as draft April 8, 2026 21:10
@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Apr 8, 2026
@alamb

This comment has been minimized.

@alamb

This comment has been minimized.

@alamb
Copy link
Copy Markdown
Contributor Author

alamb commented Apr 8, 2026

run clickbench_partitioned

@adriangbot

This comment has been minimized.

@adriangbot

This comment has been minimized.

@adriangbot

This comment has been minimized.

@adriangbot

This comment has been minimized.

@alamb alamb force-pushed the alamb/test_coverage branch from 2117a33 to 75d8e4c Compare April 9, 2026 11:16
@github-actions github-actions bot removed the sqllogictest SQL Logic Tests (.slt) label Apr 9, 2026
let mut new_offsets = BufferBuilder::<T>::new(string_array.len() + 1);
new_offsets.append(T::zero());

if let Some(ref short_re) = short_re {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to encapsulate this logic so it was easer to understand and not repeated in the two loops

/// up the pre-processing time of the replacement string, since it only
/// needs to processed once.
fn _regexp_replace_static_pattern_replace<T: OffsetSizeTrait>(
fn regexp_replace_static_pattern_replace<T: OffsetSizeTrait>(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a drive by fix, this function randomly was named starting with _ which is unecessary and unconventional

.into_owned()
}

struct ShortRegex {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to consolidate the logic for the special case short regexp optimization so

  1. It is easier to understand
  2. It is not duplicated (and thus improve test coverage)

@alamb
Copy link
Copy Markdown
Contributor Author

alamb commented Apr 9, 2026

run benchmark regx

@alamb
Copy link
Copy Markdown
Contributor Author

alamb commented Apr 9, 2026

run benchmark clickbench_partitioned

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4213803597-1011-2xg2v 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing alamb/test_coverage (75d8e4c) to 8cf70ec (merge-base) diff
BENCH_NAME=regx
BENCH_COMMAND=cargo bench --features=parquet --bench regx
BENCH_FILTER=
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4213804340-1012-s47jk 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing alamb/test_coverage (75d8e4c) to 8cf70ec (merge-base) diff using: clickbench_partitioned
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                           alamb_test_coverage                    main
-----                           -------------------                    ----
regexp_count_1000 string        1.00      2.7±0.01ms        ? ?/sec    1.01      2.7±0.01ms        ? ?/sec
regexp_count_1000 utf8view      1.00      2.8±0.02ms        ? ?/sec    1.00      2.8±0.01ms        ? ?/sec
regexp_instr_1000 string        1.00      3.3±0.01ms        ? ?/sec    1.00      3.3±0.01ms        ? ?/sec
regexp_instr_1000 utf8view      1.00      3.3±0.01ms        ? ?/sec    1.00      3.3±0.02ms        ? ?/sec
regexp_like scalar utf8         1.00     15.5±0.02µs        ? ?/sec    1.00     15.5±0.03µs        ? ?/sec
regexp_like_1000                1.00      2.8±0.01ms        ? ?/sec    1.00      2.8±0.01ms        ? ?/sec
regexp_like_1000 utf8view       1.00      2.8±0.01ms        ? ?/sec    1.00      2.9±0.01ms        ? ?/sec
regexp_match_1000               1.00      3.4±0.01ms        ? ?/sec    1.01      3.4±0.01ms        ? ?/sec
regexp_match_1000 utf8view      1.00      3.4±0.01ms        ? ?/sec    1.01      3.4±0.01ms        ? ?/sec
regexp_replace_1000             1.00      2.6±0.01ms        ? ?/sec    1.01      2.6±0.01ms        ? ?/sec
regexp_replace_1000 utf8view    1.00      2.6±0.01ms        ? ?/sec    1.00      2.6±0.01ms        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 112.0s
Peak memory 3.5 GiB
Avg memory 3.5 GiB
CPU user 135.7s
CPU sys 0.8s
Peak spill 0 B

branch

Metric Value
Wall time 110.2s
Peak memory 3.5 GiB
Avg memory 3.5 GiB
CPU user 134.7s
CPU sys 0.2s
Peak spill 0 B

File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

Comparing HEAD and alamb_test_coverage
--------------------
Benchmark clickbench_partitioned.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃                                  HEAD ┃                    alamb_test_coverage ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0  │          1.21 / 4.52 ±6.46 / 17.44 ms │           1.20 / 4.48 ±6.40 / 17.28 ms │     no change │
│ QQuery 1  │        14.15 / 14.76 ±0.34 / 15.17 ms │         14.21 / 14.75 ±0.31 / 15.12 ms │     no change │
│ QQuery 2  │        44.46 / 44.70 ±0.17 / 44.93 ms │         43.85 / 44.17 ±0.23 / 44.41 ms │     no change │
│ QQuery 3  │        44.11 / 47.24 ±2.21 / 50.90 ms │         44.68 / 45.67 ±1.35 / 48.28 ms │     no change │
│ QQuery 4  │     293.46 / 300.96 ±5.84 / 311.10 ms │     289.64 / 303.38 ±10.93 / 316.52 ms │     no change │
│ QQuery 5  │     348.46 / 351.36 ±2.18 / 354.76 ms │      347.01 / 355.55 ±7.19 / 368.84 ms │     no change │
│ QQuery 6  │           5.64 / 6.02 ±0.39 / 6.69 ms │           5.61 / 8.45 ±2.86 / 13.90 ms │  1.40x slower │
│ QQuery 7  │        16.68 / 17.26 ±0.75 / 18.73 ms │         16.82 / 17.52 ±0.79 / 18.64 ms │     no change │
│ QQuery 8  │    411.28 / 433.11 ±13.03 / 450.16 ms │     419.67 / 442.18 ±23.30 / 486.81 ms │     no change │
│ QQuery 9  │     655.03 / 671.65 ±9.20 / 681.24 ms │      658.79 / 663.90 ±7.15 / 677.83 ms │     no change │
│ QQuery 10 │        92.29 / 95.58 ±1.84 / 97.39 ms │        92.55 / 95.30 ±3.06 / 101.24 ms │     no change │
│ QQuery 11 │     104.52 / 106.09 ±0.96 / 107.15 ms │      103.72 / 105.14 ±1.16 / 107.19 ms │     no change │
│ QQuery 12 │     351.68 / 353.59 ±1.05 / 354.90 ms │      341.92 / 353.36 ±9.47 / 366.65 ms │     no change │
│ QQuery 13 │     460.78 / 472.76 ±7.24 / 481.44 ms │     459.56 / 476.35 ±15.20 / 499.68 ms │     no change │
│ QQuery 14 │     349.40 / 352.50 ±1.73 / 354.21 ms │      354.39 / 357.35 ±2.54 / 360.86 ms │     no change │
│ QQuery 15 │    353.99 / 366.99 ±13.95 / 390.08 ms │     361.62 / 377.46 ±22.47 / 421.48 ms │     no change │
│ QQuery 16 │     728.45 / 736.06 ±8.31 / 751.41 ms │     723.42 / 747.07 ±26.57 / 797.46 ms │     no change │
│ QQuery 17 │     714.42 / 717.34 ±2.19 / 719.94 ms │     713.28 / 728.64 ±25.99 / 780.55 ms │     no change │
│ QQuery 18 │ 1428.19 / 1487.65 ±43.90 / 1542.69 ms │  1403.43 / 1493.20 ±56.47 / 1569.28 ms │     no change │
│ QQuery 19 │        34.80 / 36.99 ±1.81 / 39.45 ms │         37.67 / 43.23 ±9.46 / 62.11 ms │  1.17x slower │
│ QQuery 20 │    724.15 / 741.92 ±15.61 / 761.26 ms │     720.05 / 732.82 ±14.38 / 755.83 ms │     no change │
│ QQuery 21 │     763.60 / 769.47 ±5.73 / 779.37 ms │      757.92 / 768.96 ±6.64 / 777.88 ms │     no change │
│ QQuery 22 │  1136.52 / 1142.15 ±4.91 / 1149.43 ms │   1125.28 / 1129.44 ±3.43 / 1135.20 ms │     no change │
│ QQuery 23 │  3113.44 / 3119.95 ±5.69 / 3130.16 ms │  3099.00 / 3113.07 ±10.31 / 3124.53 ms │     no change │
│ QQuery 24 │     100.98 / 103.03 ±1.52 / 104.81 ms │       98.19 / 103.08 ±4.39 / 109.93 ms │     no change │
│ QQuery 25 │     137.21 / 140.19 ±2.22 / 143.59 ms │      140.84 / 142.67 ±1.83 / 145.73 ms │     no change │
│ QQuery 26 │      99.88 / 102.26 ±2.36 / 106.25 ms │       99.50 / 102.98 ±2.55 / 105.68 ms │     no change │
│ QQuery 27 │     848.55 / 854.40 ±5.01 / 862.06 ms │      843.65 / 851.08 ±7.35 / 864.16 ms │     no change │
│ QQuery 28 │  3313.31 / 3329.45 ±9.70 / 3342.97 ms │  3223.53 / 3257.92 ±19.27 / 3278.82 ms │     no change │
│ QQuery 29 │        50.58 / 54.49 ±4.57 / 63.10 ms │         50.42 / 53.42 ±4.04 / 61.26 ms │     no change │
│ QQuery 30 │     362.02 / 368.26 ±4.81 / 373.73 ms │      358.09 / 369.46 ±6.48 / 377.62 ms │     no change │
│ QQuery 31 │     375.77 / 387.86 ±9.62 / 403.76 ms │      381.83 / 390.74 ±5.88 / 397.97 ms │     no change │
│ QQuery 32 │ 1274.58 / 1297.77 ±14.98 / 1319.95 ms │ 1040.90 / 1135.08 ±117.31 / 1361.28 ms │ +1.14x faster │
│ QQuery 33 │ 1540.87 / 1575.94 ±26.37 / 1609.31 ms │  1466.80 / 1486.04 ±18.12 / 1513.34 ms │ +1.06x faster │
│ QQuery 34 │ 1470.35 / 1510.88 ±44.71 / 1590.54 ms │  1445.00 / 1472.67 ±20.52 / 1497.81 ms │     no change │
│ QQuery 35 │     386.80 / 392.89 ±5.99 / 401.25 ms │      393.53 / 402.54 ±6.46 / 410.30 ms │     no change │
│ QQuery 36 │     118.64 / 122.59 ±2.03 / 124.34 ms │      112.82 / 121.83 ±4.99 / 126.90 ms │     no change │
│ QQuery 37 │        47.70 / 50.66 ±1.84 / 53.13 ms │         48.55 / 50.11 ±1.86 / 53.74 ms │     no change │
│ QQuery 38 │        77.97 / 78.89 ±1.13 / 81.04 ms │         75.13 / 77.14 ±1.65 / 79.95 ms │     no change │
│ QQuery 39 │     219.16 / 223.59 ±3.47 / 229.63 ms │      213.43 / 222.12 ±7.22 / 231.25 ms │     no change │
│ QQuery 40 │        26.82 / 27.88 ±0.65 / 28.82 ms │         22.12 / 26.93 ±2.85 / 30.63 ms │     no change │
│ QQuery 41 │        20.99 / 22.25 ±1.12 / 23.67 ms │         20.16 / 21.01 ±0.64 / 22.15 ms │ +1.06x faster │
│ QQuery 42 │        18.78 / 19.83 ±0.56 / 20.39 ms │         19.87 / 21.04 ±2.12 / 25.27 ms │  1.06x slower │
└───────────┴───────────────────────────────────────┴────────────────────────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary                  ┃            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (HEAD)                  │ 23053.73ms │
│ Total Time (alamb_test_coverage)   │ 22729.31ms │
│ Average Time (HEAD)                │   536.13ms │
│ Average Time (alamb_test_coverage) │   528.59ms │
│ Queries Faster                     │          3 │
│ Queries Slower                     │          3 │
│ Queries with No Change             │         37 │
│ Queries with Failure               │          0 │
└────────────────────────────────────┴────────────┘

Resource Usage

clickbench_partitioned — base (merge-base)

Metric Value
Wall time 116.4s
Peak memory 40.6 GiB
Avg memory 28.6 GiB
CPU user 1080.8s
CPU sys 104.0s
Peak spill 0 B

clickbench_partitioned — branch

Metric Value
Wall time 114.8s
Peak memory 41.3 GiB
Avg memory 30.9 GiB
CPU user 1073.1s
CPU sys 93.9s
Peak spill 0 B

File an issue against this benchmark runner

@alamb alamb marked this pull request as ready for review April 9, 2026 13:22
@alamb alamb requested a review from Dandandan April 9, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants