Skip to content

[BUG] addtotals and addcoltotals are O(n²) in the field count: numeric fields are found with a case-insensitive lookup per field #6000

Backlog

Description

@RyanL1997

Description

When no fields are given, addtotals and addcoltotals find the numeric fields with getAllNumericFields. For every field, it calls isNumericFieldName, which looks the field up again with a case-insensitive getField(fieldName, false, false). A case-insensitive lookup scans every field, so finding the numeric fields is O(n²).

This is one of two O(n²) costs in these commands. The other is a field(String) lookup per field, tracked in #5969.

Reproduce

The OpenTelemetry log index from #5991, with n attribute keys:

source=otel-logs | addtotals
source=otel-logs | addcoltotals

Before

n addtotals addcoltotals eval z = 1 | head 10
5,000 242 ms 289 ms 22 ms
10,000 872 ms 1,023 ms 29 ms
20,000 3,439 ms 3,853 ms 52 ms

The unit test below times parsing and analysis of addtotals. The plan is the same in all three rows.

n main #5969's change only #5969's change and an exact-name lookup here
5,000 278 ms 87 ms 6 ms
10,000 1,111 ms 355 ms 11 ms
20,000 4,228 ms 1,161 ms 19 ms

After

The time grows about linearly with n.

The exact-name lookup in the test was only for measurement. A case-insensitive lookup returns the first field whose name matches ignoring case, so a fix must keep that result, or deliberately change it, for indices with two fields whose names differ only in case.

Reference

Activity

  1. added
    bug
    PPL
    performance
    calcite
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PPLbugcalciteperformanceuntriaged

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions