Skip to content

[spark] Plan sorted global index builds with one scan - #11482

Open
JustinBinber wants to merge 1 commit into
apache:masterfrom
JustinBinber:codex/spark-sorted-index-bulk-union
Open

JustinBinber wants to merge 1 commit into
apache:masterfrom
JustinBinber:codex/spark-sorted-index-bulk-union

Conversation

@JustinBinber

Copy link
Copy Markdown
Contributor

Purpose

Fixes #11481.

A few table partitions can contain many disjoint RowID ranges. The identity-key sorted-index build currently constructs a separate Spark scan and projection for each range and combines them with Union. On the frozen fragmented fixture, combining the same branches with one Union still took 8.44 s before the first job.

Use one Spark scan over the existing range-filtered splits for Data Evolution builds with disjoint RowID ranges and query authorization disabled. Each row is assigned to the original build task by its RowID, with a literal task ID for single-range builds. The resulting task ID, index key and RowID feed the existing range shuffle, NULL compression and sorted writer. Other inputs use the per-range scan path.

Tests

  • Spark 3.5.9 / JDK 8: 6 Java and 8 Scala cases.
  • Spark 4.3.0 / JDK 17: 6 Java cases in Maven and 6 Scala SQL cases with the full connector classes on the test classpath.
  • Covered inclusive RowID boundaries and gaps, deletion vectors before index creation, ordinary and compressed shuffle, BTree and Bitmap incremental refresh, composite BTree, and exact query results for equality, range and NULL predicates.

Each measured build used two Paimon partitions and a private copy of the same snapshot for its fixture. The main fixture has 67 columns. Medians are from two fresh JVMs per arm and each layout was run in both orders. The baseline, bulk-Union and final one-scan runs used separate JVMs. The runs for each implementation exercised both layout orders. The dense control used ABBA order. Before-first-job time includes Paimon scan setup and Spark planning, and full build time includes index writes and snapshot commit.

Input Before first Spark job, baseline / patch Full build, baseline / patch
2 contiguous ranges, 512 data files, 4,096 rows 0.28 s / 0.28 s 2.74 s / 2.86 s
512 fragmented ranges, 512 data files, 4,096 rows 66.45 s / 0.25 s 84.36 s / 7.81 s
2 contiguous ranges, 2 data files, 100,000 rows 0.28 s / 0.22 s 1.12 s / 1.04 s

The local timings characterize this fixture. Production and multi-node speedups have not been measured.

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.

[Bug] Spark sorted global index builds spend excessive time planning fragmented RowID ranges

1 participant