Skip to content

fix: apply the Filter and date range to single-threaded reports - #349

Open
TheWitness wants to merge 1 commit into
developfrom
fix/single-thread-where
Open

TheWitness wants to merge 1 commit into
developfrom
fix/single-thread-where

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Problem

With Max Concurrent Threads (flowview_parallel_threads) set to 1, run_flow_query() builds the per-partition WHERE incorrectly:

  • Reports with one map query (most statistical and printed reports) never set $fsql_where. Every partition the time span touched was read in full, and the Filter's fields and the date range were ignored.
  • Reports with two map queries (e.g. Top Talkers by address) appended the date range to an empty string. With any Filter field set, the query began FROM plugin_flowview_raw_? AND (end_time ?) and failed with an SQL error. Without one, it produced WHERE (range) and worked only by accident.

The parallel path (threads > 1) was already correct.

Fix

Build the WHERE once per partition, before branching on the report shape, the same way the parallel path does: $sql_where, then AND/WHERE , then $sql_range. Full scans keep only $sql_where.

Tests

  • New case in tests/Unit/ParallelQueryPathTest.php covering a one-map and a two-map report with a protocol Filter over a partial range. It asserts that every FROM partition carries the Filter and the date range, and that the bound parameters match the placeholders. It fails on develop and passes with the fix.
  • Full suite: 408 passed. Patch coverage 100%.

Found while reworking the NBAR support for #297.

With Max Concurrent Threads at 1, run_flow_query() built the WHERE of a
partition only for reports with two map queries, and there it appended
the date range to an empty string: with a Filter field set the query
began ' AND (end_time ...)' and failed, and the Filter itself was lost.
Reports with one map query had no WHERE at all, so the Filter and the
date range were ignored.

Build the WHERE once per partition for both report shapes, as the
parallel path does.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 5, 2026 18:57
@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

One-map reports fail with an SQL syntax error when Listener is All and a specific Stream is selected because the Stream clause lacks WHERE; the fix and a regression test are needed.

1 open issue
What changed in this PR

Corrects FlowView’s single-threaded report queries so partition reads apply saved Filters and the requested date range.

Changes:

  • Builds partition predicates before branching between one-map and two-map reports.
  • Adds regression coverage for both report shapes and parameter counts.
  • Documents the fix in the changelog.
File Description
tests/​Unit/​ParallelQueryPathTest.php Tests Filter and date predicates in single-threaded queries.
includes/​functions.php Shares partition predicate construction across report shapes.
CHANGELOG.md Records the single-threaded reporting fix.

Review effort: Balanced

Comment thread includes/functions.php
$fsql_params = $sql_params;
}
if (!$full_scan) {
$fsql_where = $sql_where . ($sql_where != '' ? ' AND ':'WHERE ') . $sql_range;

@somethingwithproof somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. Reproduced on develop: with Max Concurrent Threads disabled, a one-map report read every row (filter and range ignored) and a two-map report failed with a SQL syntax error. On this head the serial and parallel paths build the same WHERE clause and parameters per partition and return identical results on MariaDB 10.11 and MySQL 8.4; filter values are parameterized. The new test fails on develop and passes here on PHP 8.2 and 8.6.

Nit: the serial path still uses its own full-scan test without the live-partition guard flowview_is_full_scan() applies on the parallel path (includes/functions.php:3989). Results are correct; it's a consistency point for later.

This should merge before #297, whose Applications filter has the same single-thread gap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants