Data Auto Sharding and Auto Indexing: Difference between revisions
No edit summary |
Wikiservice (talk | contribs) (Refresh MemCP documentation: accuracy, operational guidance, performance profile and maintained API reference) |
||
| Line 1: | Line 1: | ||
<!-- Copyright (C) 2026 Carl-Philip Haensch --> | |||
<!-- SPDX-License-Identifier: GPL-3.0-or-later --> | |||
<span id="data-auto-sharding-and-auto-indexing"></span> | |||
= Data Auto Sharding and Auto Indexing = | |||
MemCP observes executed scans and uses their boundaries, ordering, selectivity, and row counts as evidence for physical organization. It can build adaptive indexes and use partitioning hints during later shard rebuilds, reducing the need to predict every access path when defining a schema. | |||
This self-tuning behavior is incremental rather than instantaneous: small shards and weak evidence deliberately avoid expensive builds, while repartitioning happens as background physical maintenance. The choices never change SQL semantics and do not replace logical decorrelation, join ordering, transaction visibility, or residual predicate checks. Operators should still inspect plans and resource use for important workloads. | |||
Unlike a declared primary or unique key, an adaptive index is a performance object rather than a data-integrity rule. Keep schema constraints that protect correctness; let workload evidence propose additional physical access paths. | |||
== | <span id="adaptive-indexes"></span> | ||
== Adaptive indexes == | |||
Equality, range, IN-list, LIKE-prefix, computed-expression, and ordering boundaries describe useful index prefixes. MemCP reuses compatible longer indexes, avoids new indexes for tiny shards, and accumulates estimated savings until build cost is amortized. ORDER/LIMIT scans receive a weighted benefit so a small top-k does not train an expensive full index as aggressively as a broad ordered scan. | |||
Indexes contain compressed record-ID permutations rather than copies of column values. Main rows and delta inserts are both ordered: an index-local delta tree is merged with the main permutation during iteration. Deleted/invisible rows and residual predicates remain subject to transaction visibility and filtering. | |||
Relevant settings are <code>IndexThreshold</code>, <code>AnalyzeMinItems</code>, <code>ScanDebugging</code>, and <code>ShardSize</code>. | |||
The benefit estimate compares continued full-scan work, index build cost, and future indexed probes. Until estimated savings amortize the build, MemCP can continue scanning. This avoids eagerly creating every syntactically possible index and lets a compatible longer index serve a shorter prefix. | |||
== | <span id="adaptive-sharding"></span> | ||
== Adaptive sharding == | |||
Scans contribute partitioning evidence for useful columns. Rebuild/repartition work uses these hints, row counts, <code>ShardSize</code>, CPU parallelism, and <code>PartitionMaxDimensions</code> to choose shard boundaries. Bulk inserts create and rebuild shards in batches; readers and writers are protected during generation replacement. | |||
Repartitioning is background physical maintenance. It may consume CPU, memory, and storage bandwidth, so observe it on large production tables. It must preserve writes and durability across old and new shard generations. | |||
Useful partitioning lets a bounded scan skip unrelated shards and lets independent shards execute concurrently. It is not the same as distributing tables across network nodes: current adaptive sharding is local to one MemCP instance. | |||
== Bulk import and operational guidance == | |||
Large inserts are chunked around the configured shard target and full shards can rebuild in parallel. Loading in batches is more efficient than a client round trip per row and gives the analyzer enough evidence to select compact representations. After a representative warm-up, inspect <code>EXPLAIN PHYSICAL</code>, shard statistics, resident memory, build activity, and query latency. | |||
=== | |||
Avoid tuning <code>ShardSize</code> or <code>PartitionMaxDimensions</code> from a single query. Very small shards add scheduling/index metadata overhead; very large shards reduce pruning and parallel choices. Validate changes with the complete read/write workload and restart behavior. | |||
The current defaults are <code>ShardSize=60000</code> and <code>PartitionMaxDimensions=10</code>. They are starting points, not a promise that every table will have exactly 60,000 rows per shard or use ten dimensions. | |||
== Historical parallel-scan observation == | |||
An earlier development run reported 1,500–1,900% CPU utilization on a 24-core host, a 3–6× improvement over its single-shard comparison and roughly 0.04 µs per row for simple COUNT/SUM work. The old page did not preserve the commit, dataset, query, repetitions, correctness checks or machine state, so these numbers remain a useful engineering observation rather than a current benchmark claim. Reproduce them with [[Performance Measurement|the performance framework]] before using them for capacity planning. | |||
See [[Query_Planner_and_Physical_Lowering|Query Planner and Physical Lowering]] for the cost model that decides whether a query uses an index, direct scan, RecSet, cache, or another scan source. [[RecSets]] explains how exact and candidate memberships interact with these indexes and adapt between ranges, sparse IDs, and bitmaps. | |||
| | |||
| | |||
Latest revision as of 11:59, 28 August 2026
Data Auto Sharding and Auto Indexing
MemCP observes executed scans and uses their boundaries, ordering, selectivity, and row counts as evidence for physical organization. It can build adaptive indexes and use partitioning hints during later shard rebuilds, reducing the need to predict every access path when defining a schema.
This self-tuning behavior is incremental rather than instantaneous: small shards and weak evidence deliberately avoid expensive builds, while repartitioning happens as background physical maintenance. The choices never change SQL semantics and do not replace logical decorrelation, join ordering, transaction visibility, or residual predicate checks. Operators should still inspect plans and resource use for important workloads.
Unlike a declared primary or unique key, an adaptive index is a performance object rather than a data-integrity rule. Keep schema constraints that protect correctness; let workload evidence propose additional physical access paths.
Adaptive indexes
Equality, range, IN-list, LIKE-prefix, computed-expression, and ordering boundaries describe useful index prefixes. MemCP reuses compatible longer indexes, avoids new indexes for tiny shards, and accumulates estimated savings until build cost is amortized. ORDER/LIMIT scans receive a weighted benefit so a small top-k does not train an expensive full index as aggressively as a broad ordered scan.
Indexes contain compressed record-ID permutations rather than copies of column values. Main rows and delta inserts are both ordered: an index-local delta tree is merged with the main permutation during iteration. Deleted/invisible rows and residual predicates remain subject to transaction visibility and filtering.
Relevant settings are IndexThreshold, AnalyzeMinItems, ScanDebugging, and ShardSize.
The benefit estimate compares continued full-scan work, index build cost, and future indexed probes. Until estimated savings amortize the build, MemCP can continue scanning. This avoids eagerly creating every syntactically possible index and lets a compatible longer index serve a shorter prefix.
Adaptive sharding
Scans contribute partitioning evidence for useful columns. Rebuild/repartition work uses these hints, row counts, ShardSize, CPU parallelism, and PartitionMaxDimensions to choose shard boundaries. Bulk inserts create and rebuild shards in batches; readers and writers are protected during generation replacement.
Repartitioning is background physical maintenance. It may consume CPU, memory, and storage bandwidth, so observe it on large production tables. It must preserve writes and durability across old and new shard generations.
Useful partitioning lets a bounded scan skip unrelated shards and lets independent shards execute concurrently. It is not the same as distributing tables across network nodes: current adaptive sharding is local to one MemCP instance.
Bulk import and operational guidance
Large inserts are chunked around the configured shard target and full shards can rebuild in parallel. Loading in batches is more efficient than a client round trip per row and gives the analyzer enough evidence to select compact representations. After a representative warm-up, inspect EXPLAIN PHYSICAL, shard statistics, resident memory, build activity, and query latency.
Avoid tuning ShardSize or PartitionMaxDimensions from a single query. Very small shards add scheduling/index metadata overhead; very large shards reduce pruning and parallel choices. Validate changes with the complete read/write workload and restart behavior.
The current defaults are ShardSize=60000 and PartitionMaxDimensions=10. They are starting points, not a promise that every table will have exactly 60,000 rows per shard or use ten dimensions.
Historical parallel-scan observation
An earlier development run reported 1,500–1,900% CPU utilization on a 24-core host, a 3–6× improvement over its single-shard comparison and roughly 0.04 µs per row for simple COUNT/SUM work. The old page did not preserve the commit, dataset, query, repetitions, correctness checks or machine state, so these numbers remain a useful engineering observation rather than a current benchmark claim. Reproduce them with the performance framework before using them for capacity planning.
See Query Planner and Physical Lowering for the cost model that decides whether a query uses an index, direct scan, RecSet, cache, or another scan source. RecSets explains how exact and candidate memberships interact with these indexes and adapt between ranges, sparse IDs, and bitmaps.