GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — CREATE INDEX on a populated type: the sorted build sizes its runs at 3,072 bytes per entry and spills, so at 6M rows it is barely faster than the default build; in one pass it halves it · Issue #10267 · ArcadeData/arcadedb

CREATE INDEX on a populated type: the sorted build sizes its runs at 3,072 bytes per entry and spills, so at 6M rows it is barely faster than the default build; in one pass it halves it #10267

New issue
Copy link
New issue
Copy link
Closed
#10422
Closed
CREATE INDEX on a populated type: the sorted build sizes its runs at 3,072 bytes per entry and spills, so at 6M rows it is barely faster than the default build; in one pass it halves it#10267
#10422
Copy link
Assignees
lvca
Labels
engineCore engine: document/schema APIperformanceseverity:minorCosmetic, documentation, edge case, or a workaround existssql
Milestone
26.11.1

Description

@tae898
tae898
opened on Oct 18, 2026
Issue body actions

CREATE INDEX on a populated type: the sorted build of #9299 sizes its runs by a fixed 3,072 bytes per entry, so at 6,000,000 rows it spills and is only a little faster than the default build. In one pass it takes about half the default build's time. The default build is still the transactional path.

Setup: the documents lane of my benchmark, scaled to TPC-H SF1's lineitem. Type LineItem with BUCKETS 8 and its 11 typed columns, and 6,000,000 records whose l_shipdate is a STRING 'YYYY-MM-DD' over TPC-H's 2526 ship dates. Then CREATE INDEX ON LineItem (l_shipdate) NOTUNIQUE is timed in each build mode, alternating on the same data, with DROP INDEX between. Each build is checked: 6,000,000 entries, and a one-year range count equal to the generator's. eclipse-temurin 25 (-XX:+UseCompactObjectHeaders), -Xmx5g, 4 cores, 3 builds per mode:

build main cdaade99c1 26.10.2 e5040d0339 26.10.1
default (CREATE INDEX ... NOTUNIQUE) 7.3-7.6 s 7.1-7.4 s 7.1-7.4 s
METADATA {buildMode: 'SORTED'} 6.2-6.6 s 6.1-6.6 s -
sorted, Java API withBuildParallelism(4) 5.7-6.4 s 5.7-6.4 s -

The sorted build logs the reason. With the budget it resolves here, memoryBudget=1.06GB maxEntriesPerRun=372,113, it ends with finalRuns=3 spillBytes=140.92MB. LSMTreeIndexBulkLoader divides the budget by ESTIMATED_BYTES_PER_ENTRY = 3_072 (times 8 once the keys are shared). Its own comment puts an entry of a shared run at about 100 bytes. Given 4 GB with withBuildMemoryBudget (main, the same data):

build runs spilled time heap peak above the level before the build
sorted, resolved budget (1.06GB) 3 final runs, 140.92MB 6.1-6.7 s 678-1428 MB
sorted, 4 GB budget, 1 thread 0, 0b 3.9-4.2 s 817-1363 MB
sorted, 4 GB budget, 4 threads 0, 0b 3.6-3.8 s -
default - 7.2-7.4 s 1326-1455 MB

(The heap peaks are sampled every 20 ms and include garbage, so they are rough.) The one-pass build peaks in the same range as the spilling one and below the default build. It does not need four times the memory: what the 3,072-byte estimate limits is the run size.

Where the time goes (JFR execution samples of one build each, main):

  • default: 23.1% under TransactionIndexContext.addIndexKeyLock, 16.1% in TransactionIndexContext$ComparableKey.compareTo, and 10.9% in TransactionIndexContext.commit: the per-key transaction bookkeeping a bulk build over existing records does not need.
  • sorted, resolved budget: 11.9% in spillCurrentRun, 9.8% in RunReader.advance and 9.3% in MergedCursor.next: the spill and the merge.

Two suggestions, either of which shortens the build:

  1. Size the runs from what an entry takes. A measured or per-key-type estimate in place of 3,072 bytes would let this build run in one pass or close to it; in one pass it is about 1.8x faster than the default build here.
  2. Use the sorted build by default for CREATE INDEX on a populated type, at least for UNIQUE and NOTUNIQUE LSM indexes, where fix: anti-join count push-down shapes and sorted index build for low-cardinality keys (#9290, #9291) #9299 found it gives the same index.

For scale: on my benchmark host the documents lane's index build at SF1 took 6.13 s for ArcadeDB 26.10.1 (embedded) against 1.45 s for PostgreSQL, the median of 3 runs each in my current pass. The laptop numbers above are for ratios only.

IndexBuildModes.java
// type: LineItem with the lane's column types and BUCKETS, N rows, l_shipdate a STRING 'YYYY-MM-DD' over TPC-H's 2,526 ship
// dates; then CREATE INDEX ON LineItem (l_shipdate) NOTUNIQUE timed in the DEFAULT and the SORTED build mode, alternating on
// the same data (DROP INDEX between), each build checked: entries = N and a one-year range count = the generator's count.
//   java IndexBuildModes.java <dir> <rows> <buckets> <reps> [modes=DEFAULT,SORTED; SORTED_P<n> = the Java API's SORTED build with n threads]
import com.arcadedb.database.*;
import com.arcadedb.index.*;
import com.arcadedb.schema.*;
import java.time.LocalDate;
import java.util.*;

public class IndexBuildModes {
  public static void main(String[] a) throws Exception {
    String dir = a[0]; long n = Long.parseLong(a[1]); int buckets = Integer.parseInt(a[2]), reps = Integer.parseInt(a[3]); String[] order = (a.length > 4 ? a[4] : "DEFAULT,SORTED").split(",");
    DatabaseFactory f = new DatabaseFactory(dir); if (f.exists()) f.open().drop(); Database db = f.create();
    db.command("sql", "CREATE DOCUMENT TYPE LineItem BUCKETS " + buckets).close();
    String[][] cols = { {"l_orderkey","LONG"},{"l_partkey","LONG"},{"l_suppkey","LONG"},{"l_quantity","DOUBLE"},{"l_extendedprice","DOUBLE"},
        {"l_discount","DOUBLE"},{"l_tax","DOUBLE"},{"l_returnflag","STRING"},{"l_linestatus","STRING"},{"l_shipdate","STRING"},{"l_shipmode","STRING"} };
    for (String[] c : cols) db.command("sql", "CREATE PROPERTY LineItem." + c[0] + " " + c[1]).close();
    LocalDate d0 = LocalDate.of(1992, 1, 2); int days = (int) (LocalDate.of(1998, 12, 1).toEpochDay() - d0.toEpochDay()) + 1;
    String[] dates = new String[days]; for (int i = 0; i < days; i++) dates[i] = d0.plusDays(i).toString();
    String[] modes = { "AIR", "FOB", "MAIL", "RAIL", "REG AIR", "SHIP", "TRUCK" };
    Random r = new Random(42); long inYear = 0; long t0 = System.nanoTime();
    final int BATCH = 20_000;
    for (long i = 0; i < n; ) {
      db.begin();
      for (int b = 0; b < BATCH && i < n; b++, i++) {
        String sd = dates[r.nextInt(days)]; if (sd.compareTo("1994-01-01") >= 0 && sd.compareTo("1995-01-01") < 0) inYear++;
        db.newDocument("LineItem").set("l_orderkey", i / 4).set("l_partkey", (long) r.nextInt(200_000)).set("l_suppkey", (long) r.nextInt(10_000))
          .set("l_quantity", (double) (1 + r.nextInt(50))).set("l_extendedprice", 900.0 + r.nextInt(100_000) / 1.0).set("l_discount", r.nextInt(11) / 100.0)
          .set("l_tax", r.nextInt(9) / 100.0).set("l_returnflag", r.nextBoolean() ? "N" : "R").set("l_linestatus", r.nextBoolean() ? "O" : "F")
          .set("l_shipdate", sd).set("l_shipmode", modes[r.nextInt(modes.length)]).save();
      }
      db.commit();
    }
    System.out.printf("LOAD rows %d buckets %d in %.1f s; distinct ship dates %d; rows in 1994: %d%n", n, buckets, (System.nanoTime() - t0) / 1e9, days, inYear);
    for (int rep = 1; rep <= reps; rep++) for (String mode : rotate(order, rep - 1)) {
      if (db.getSchema().existsIndex("LineItem[l_shipdate]")) db.getSchema().dropIndex("LineItem[l_shipdate]");
      System.gc(); Thread.sleep(2000);
      jdk.jfr.Recording jr = null;
      if (System.getenv("JFR_DIR") != null && rep == 1) { jr = new jdk.jfr.Recording(); jr.enable("jdk.ExecutionSample").withPeriod(java.time.Duration.ofMillis(5)); jr.start(); }
      var mx = java.lang.management.ManagementFactory.getMemoryMXBean(); System.gc(); Thread.sleep(500); final long base = mx.getHeapMemoryUsage().getUsed();
      final long[] peak = { base }; final boolean[] run = { true };
      Thread sampler = new Thread(() -> { while (run[0]) { peak[0] = Math.max(peak[0], mx.getHeapMemoryUsage().getUsed()); try { Thread.sleep(20); } catch (InterruptedException ie) { return; } } });
      sampler.setDaemon(true); sampler.start();
      long s = System.nanoTime();
      if (mode.startsWith("SORTED_")) {   // SORTED_P<threads>[_M<GiB>]: the Java API's sorted build, with a thread count and a memory budget
        var m = java.util.regex.Pattern.compile("SORTED_P(\\d+)(?:_M(\\d+))?").matcher(mode); if (!m.matches()) throw new IllegalArgumentException(mode);
        var tb = db.getSchema().buildTypeIndex("LineItem", new String[] { "l_shipdate" }).withBuildMode(IndexBuildMode.SORTED).withBuildParallelism(Integer.parseInt(m.group(1)));
        if (m.group(2) != null) tb = tb.withBuildMemoryBudget(Long.parseLong(m.group(2)) << 30);
        tb.withType(Schema.INDEX_TYPE.LSM_TREE).withUnique(false).create();
      }
      else db.command("sql", "CREATE INDEX ON LineItem (l_shipdate) NOTUNIQUE" + (mode.equals("SORTED") ? " METADATA {buildMode: 'SORTED'}" : "")).close();
      double ms = (System.nanoTime() - s) / 1e6; run[0] = false; sampler.join(); long heapMb = (peak[0] - base) >> 20;
      if (jr != null) { jr.stop(); jr.dump(java.nio.file.Path.of(System.getenv("JFR_DIR"), "build-" + mode + ".jfr")); jr.close(); }
      long entries = db.getSchema().getIndexByName("LineItem[l_shipdate]").countEntries();
      long q; try (var rs = db.query("sql", "SELECT count(*) AS c FROM LineItem WHERE l_shipdate >= '1994-01-01' AND l_shipdate < '1995-01-01'")) { q = ((Number) rs.next().getProperty("c")).longValue(); }
      System.out.printf("RESULT rep %d mode %s build_ms %.0f heap_peak_over_base_mb %d entries %d (want %d) year_count %d (want %d) %s%n", rep, mode, ms, heapMb, entries, n, q, inYear,
          entries == n && q == inYear ? "ok" : "WRONG");
    }
    db.close();
  }
  static String[] rotate(String[] m, int k) { String[] o = new String[m.length]; for (int i = 0; i < m.length; i++) o[i] = m[(i + k) % m.length]; return o; }
}

Activity

  1. github-actions
    added
    engineCore engine: document/schema API
    performance
    severity:minorCosmetic, documentation, edge case, or a workaround exists
    sql
    on Oct 18, 2026
  2. robfrank
    added this to the 26.11.1 milestone on Oct 18, 2026
  3. tae898 commented on Oct 18, 2026

    @tae898
    tae898
    on Oct 18, 2026
    ContributorAuthor
    More actions

    A correction to the numbers above, from a clean A/B. The table in the description was measured on four cores while another job ran and the package sat at 68-91 C. Repeated on P cores 2-3 with nothing else running and the package at most 66 C at each start (a 65 C gate with a 15-minute cap), with one fresh JVM per build (load the 6,000,000 records, then one CREATE INDEX), the two arms alternating per pair, 9 pairs plus a warm-up, main cdaade99c1, JDK 25:

    build median
    default 5.33 s and 5.34 s (the two series)
    METADATA {buildMode: 'SORTED'}, the resolved budget (spills) 5.39 s
    sorted, withBuildMemoryBudget(4 GB) (no spill) 3.34 s

    No spill against default: B/A = 0.631, 95% interval [0.615, 0.643], faster in 8 of 8 clean pairs. So without the spill the sorted build is about 1.6x faster than the default build (37% less time), not the 1.8x I wrote above. At the resolved budget it gains nothing over the default build here (5 clean pairs; the 1.15x in the description came from the noisy run). Both points make the same case: the sorted build's gain is all in not spilling.

  4. tae898 commented on Oct 18, 2026

    @tae898
    tae898
    on Oct 18, 2026
    ContributorAuthor
    More actions

    With more pairs under the same clean conditions (11 clean pairs over two series): buildMode: 'SORTED' at the resolved budget against the default build, B/A = 1.021, 95% interval [0.974, 1.037], slower in 6 and faster in 5 of 11 pairs. So it is no faster than the default build here, and the whole gain of the sorted build is in not spilling (0.631 [0.615, 0.643] with a 4 GB budget).

  5. lvca
    added
    in progressThe team is actively working on this issue
    on Oct 19, 2026
  6. lvca
    self-assigned this
    on Oct 19, 2026
  7. lvca
    added 4 commits that reference this issue on Oct 19, 2026

    fix(#10267): follow the size of the keys with a moving average, so a …

    b64d292

    fix(#10267): a key size that rises moves the average faster than one …

    c477aab

    test(#10267): use count() for the ground-truth query

    914890c

    fix(#10420, #10412, #10267): a sub-index names the type owning its bu…

    74282bf
  8. lvca
    closed this as completedin #10422on Oct 20, 2026
  9. lvca commented on Oct 20, 2026

    @lvca
    lvca
    on Oct 20, 2026
    Member
    More actions

    Fixed in #10422, released in 26.11.1.

    The sorted index build assumed a fixed 3,072 bytes per entry for its in-memory runs, about 20 times what a short key takes, so it spilled to disk although the data fitted. It now sizes the runs by the memory the entries really use.

    3,000,000 LineItem rows with a date string key (8 buckets, 2.5 GB heap): the default build takes 2.3 s, the sorted build 1.4 s in one pass (before: 2.2 s with 2 spilled runs). Your 6M-row A/B measured 0.62x the default build's time.

    Also, as you suggested: CREATE INDEX ... NOTUNIQUE on a type with 1,000,000 or more records now takes the sorted build by default. Set arcadedb.index.buildSortedNonUniqueMinRecords to 0 to turn it off. Documented in the settings and CREATE INDEX pages.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  10. lvca
    removed
    in progressThe team is actively working on this issue
    on Oct 20, 2026
  11. robfrank
    added a commit that references this issue on Nov 5, 2026

    fix(#10420, #10412, #10267): a sub-index names the type owning its bu…

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

Metadata

Metadata

Assignees

  • @lvca
    lvca

Labels

engineCore engine: document/schema APIperformanceseverity:minorCosmetic, documentation, edge case, or a workaround existssql

Type

No type

Projects

No projects

    Milestone

    • 26.11.1

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.