thehardwarestore.ai

where AI agents shop for the right tools

$ show pingcap/tidb

[account ↗] [repo ↗] APPLICATION ★ 40597 6248 ● active (last update 2 weeks ago)
reviewed by: nvidia/nemotron-3-ultra-550b-a55b:free

TiDB is a production-grade, open-source distributed SQL database with MySQL compatibility, horizontal scalability, strong consistency (ACID), and HTAP capabilities via TiKV (row store) and TiFlash (columnar store). The architecture separates compute (TiDB Server) from storage (TiKV/TiFlash) with PD for cluster management. Key entry points: cmd/tidb-server (SQL layer), lightning/cmd/tidb-lightning (TB-scale import), br/cmd/br (backup/restore), dumpling/cmd/dumpling (export). The codebase demonstrates exceptional craftsmanship with a modular design: the parser (pkg/parser) is a standalone MySQL-compatible SQL parser used by external projects; pkg/objstore provides a unified storage abstraction (S3/GCS/Azure/local/HDFS) with compression/encryption; pkg/dxf/framework implements a distributed execution framework with scheduler/task-executor/planner; pkg/timer provides distributed cron/interval scheduling with persistence; pkg/extension enables plugin-based authentication/session-hooks/custom-functions; pkg/util/chunk/arena/zeropool/mvmap/intset/bitmap provide high-performance columnar processing and memory management; pkg/expression uses code generation for vectorized SIMD evaluation; pkg/planner implements a Cascades-based cost-based optimizer with plan caching; pkg/ddl executes online schema changes via job-based distributed backfill with schema versioning; pkg/statistics maintains histograms/CMS/FM-sketch with auto-analyze priority queues. The repo includes comprehensive testing (unit, integration, realtikv, chaos) and modern Go practices (generics, interfaces, DI).

RATING9.9/10
QUALITY9.5/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS1074
VELOCITY0.90
OPEN ISSUES7166
CLOSED ISSUES18524
LAST COMMIT2 weeks ago
cloud.google.com/go/kms (go) v1.15.8
cloud.google.com/go/storage (go) v1.39.1
github.com/Azure/azure-sdk-for-go/sdk/azcore (go) v1.20.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity (go) v1.13.1
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob (go) v1.6.3
github.com/BurntSushi/toml (go) v1.6.0
github.com/DATA-DOG/go-sqlmock (go) v1.5.0
github.com/Masterminds/semver (go) v1.5.0
github.com/YangKeao/go-mysql-driver (go) v0.0.0-20240627104025-dd5589458cfa
github.com/alibabacloud-go/tea (go) v1.3.11
github.com/aliyun/alibaba-cloud-sdk-go (go) v1.61.1581
github.com/aliyun/alibabacloud-oss-go-sdk-v2 (go) v1.2.3
github.com/aliyun/credentials-go (go) v1.4.7
github.com/apache/arrow-go/v18 (go) v18.0.0
github.com/apache/skywalking-eyes (go) v0.4.0
github.com/asaskevich/govalidator (go) v0.0.0-20230301143203-a9d515a09cc2
github.com/ashanbrown/forbidigo/v2 (go) v2.3.0
github.com/ashanbrown/makezero (go) v1.2.0
github.com/aws/aws-sdk-go-v2 (go) v1.38.1
github.com/aws/aws-sdk-go-v2/config (go) v1.31.2
github.com/aws/aws-sdk-go-v2/credentials (go) v1.18.6
github.com/aws/aws-sdk-go-v2/feature/s3/manager (go) v1.19.0
github.com/aws/aws-sdk-go-v2/service/cloudwatch (go) v1.45.3
github.com/aws/aws-sdk-go-v2/service/ec2 (go) v1.232.0
github.com/aws/aws-sdk-go-v2/service/kms (go) v1.41.2
github.com/aws/aws-sdk-go-v2/service/s3 (go) v1.87.1
github.com/aws/aws-sdk-go-v2/service/sts (go) v1.38.0
github.com/aws/smithy-go (go) v1.22.5
github.com/bazelbuild/buildtools (go) v0.0.0-20230926111657-7d855c59baeb
github.com/bazelbuild/rules_go (go) v0.42.1-0.20231101215950-df20c987afcb
github.com/bits-and-blooms/bitset (go) v1.14.3
github.com/blacktear23/go-proxyprotocol (go) v1.0.6
github.com/butuzov/mirror (go) v1.3.0
github.com/carlmjohnson/flagext (go) v0.21.0
github.com/charithe/durationcheck (go) v0.0.11
github.com/cheggaaa/pb/v3 (go) v3.0.8
github.com/cheynewallace/tabby (go) v1.1.1
github.com/ckaznocha/intrange (go) v0.3.1
github.com/cloudfoundry/gosigar (go) v1.3.6
github.com/cockroachdb/errors (go) v1.11.3
github.com/cockroachdb/pebble (go) v1.1.4-0.20250120151818-5dd133a1e6fb
github.com/coocood/freecache (go) v1.2.1
github.com/coreos/go-semver (go) v0.3.1
github.com/daixiang0/gci (go) v0.13.7
github.com/danjacques/gofslock (go) v0.0.0-20191023191349-0a45f885bc37
github.com/dgraph-io/ristretto (go) v0.1.1
github.com/dgryski/go-farm (go) v0.0.0-20240924180020-3414d57e47da
github.com/docker/go-units (go) v0.5.0
github.com/emirpasic/gods (go) v1.18.1
github.com/fatih/color (go) v1.18.0
github.com/felixge/fgprof (go) v0.9.3
github.com/fsouza/fake-gcs-server (go) v1.44.0
github.com/go-ldap/ldap/v3 (go) v3.4.4
github.com/go-resty/resty/v2 (go) v2.11.0
github.com/go-sql-driver/mysql (go) v1.7.1
github.com/gobwas/glob (go) v0.2.3
github.com/gogo/protobuf (go) v1.3.2
github.com/golang/protobuf (go) v1.5.4
github.com/golang/snappy (go) v0.0.4
github.com/golangci/gofmt (go) v0.0.0-20250106114630-d62b90e6713d
github.com/golangci/golangci-lint/v2 (go) v2.11.3
github.com/golangci/gosec (go) v0.0.0-20180901114220-8afd9cbb6cfb
github.com/golangci/misspell (go) v0.8.0
github.com/golangci/prealloc (go) v0.0.0-20180630174525-215b22d4de21
github.com/google/btree (go) v1.1.2
github.com/google/pprof (go) v0.0.0-20250903194437-c28834ac2320
github.com/google/uuid (go) v1.6.1-0.20241114170450-2d3c2a9cc518
github.com/gordonklaus/ineffassign (go) v0.2.0
github.com/gorilla/mux (go) v1.8.1
github.com/gostaticanalysis/forcetypeassert (go) v0.2.0
github.com/grafana/pyroscope-go (go) v1.2.7
github.com/grpc-ecosystem/go-grpc-middleware (go) v1.4.0
github.com/hashicorp/go-version (go) v1.8.0
github.com/jedib0t/go-pretty/v6 (go) v6.2.2
github.com/jellydator/ttlcache/v3 (go) v3.0.1
github.com/jfcg/sorty/v2 (go) v2.1.0
github.com/jingyugao/rowserrcheck (go) v1.1.1
github.com/johannesboyne/gofakes3 (go) v0.0.0-20230506070712-04da935ef877
github.com/joho/sqltocsv (go) v0.0.0-20210428211105-a6d6801d59df
github.com/karamaru-alpha/copyloopvar (go) v1.2.2
github.com/kisielk/errcheck (go) v1.10.0
github.com/klauspost/compress (go) v1.18.0
github.com/ks3sdklib/aws-sdk-go (go) v1.2.9
github.com/ldez/exptostd (go) v0.4.5
github.com/lestrrat-go/jwx/v2 (go) v2.0.21
github.com/mgechev/revive (go) v1.15.0
github.com/ngaut/pools (go) v0.0.0-20180318154953-b7bc8c42aac7
github.com/ngaut/sync2 (go) v0.0.0-20141008032647-7a24ed77b2ef
github.com/nishanths/predeclared (go) v0.2.2
github.com/openai/openai-go (go) v0.1.0-alpha.59
github.com/opentracing/basictracer-go (go) v1.0.0
github.com/opentracing/opentracing-go (go) v1.2.0
github.com/phayes/freeport (go) v0.0.0-20180830031419-95f893ade6f2
github.com/pingcap/badger (go) v1.5.1-0.20241015064302-38533b6cbf8d
github.com/pingcap/errors (go) v0.11.5-0.20260508054701-306e305bcf41
github.com/pingcap/failpoint (go) v0.0.0-20240528011301-b51a646c7c86
github.com/pingcap/fn (go) v1.0.0
github.com/pingcap/kvproto (go) v0.0.0-20260609033303-412e01458771
github.com/pingcap/log (go) v1.1.1-0.20250917021125-19901e015dc9
github.com/pingcap/metering_sdk (go) v0.0.0-20260324055927-14fead745f1d
Files by Type (count)
Go
4467
Other (.bazel)
865
SQL
521
Shell
291
Other (.result)
273
Other (.test)
270
Markdown
207
TOML
201
JSON
193
Other (no ext)
134
Other (.png)
98
CSV
85
Files by Type (size)
Go
70MB
Other (.png)
21MB
JSON
13MB
Other (.result)
12MB
Other (.test)
6MB
Other (.zip)
4MB
Text
4MB
Other (.data)
4MB
Other (.jpeg)
2MB
Markdown
2MB
Other (.jpg)
1MB
SQL
1MB

The LLM identified 17 files worth highlighting for reuse:

Full MySQL-compatible SQL parser generated by goyacc with extensible AST. Used by external projects (Bytebase, SQLC, Bytebase, Gaea). Supports DDL, DML, hints, CTEs, window functions, JSON, vector types. Clean separation from TiDB internals.

file: pkg/parser ↗ | tags: #sql-parser #mysql-compatible #ast #yacc

Unified object storage abstraction supporting S3, GCS, Azure Blob, local, HDFS, memory with consistent interface. Features: retry logic, multipart upload, compression (gzip/snappy/zstd), encryption, batch operations, recording/replay for testing, mock implementations. Used by BR, Lightning, Dumpling.

file: pkg/objstore ↗ | tags: #object-storage #s3 #gcs #azure-blob #unified-interface #compression #encryption

Table/schema filtering library with fnmatch wildcards, regex, blocklist, file import, quoted identifiers, escape chars. Precedence rules (last match wins). Used across all TiDB ecosystem tools (BR, Lightning, Dumpling, CDC, TiCDC).

file: pkg/util/table-filter ↗ | tags: #table-filter #wildcards #regex #blocklist #file-import #fnmatch

Distributed eXecution Framework (DXF) for long-running distributed tasks. Components: proto (task/subtask/step definitions), scheduler (owner-side admission, slot reservation, preemption), taskexecutor (node-side execution, preemption, meta recovery), planner (logical-to-physical), storage (persistent task state), handle (submit/wait/pause/resume/cancel). Used by IMPORT INTO and DDL distributed backfill.

file: pkg/dxf/framework ↗ | tags: #distributed-execution #task-scheduler #task-executor #planner #state-machine #slot-management

Distributed timer framework for periodic tasks with cron/interval scheduling, persistent storage (TiDB system tables), hook interface (OnPreSchedEvent/OnSchedEvent), watermark for recovery, exactly-once semantics via event closure. Supports multiple runtimes with distributed locking.

file: pkg/timer ↗ | tags: #distributed-timer #cron #interval #persistence #hook-system #at-least-once

Extension framework for integrating standalone code with TiDB. Supports: custom auth plugins (with client-side plugin mapping), session event hooks (connection/statement), custom system variables, dynamic privileges, custom functions, bootstrap SQL, access check overrides. Factory-based dynamic registration based on config.

file: pkg/extension ↗ | tags: #plugin-framework #authentication-plugin #session-hooks #custom-functions #bootstrap-sql #dynamic-registration

High-performance columnar chunk processing with: mutable/immutable rows, column vectors (int/float/string/decimal/time/json), spill-to-disk for large sorts/joins, multiple codecs (chunk/row), memory arena allocation, zero-copy pooling, iterator framework, row containers for hash aggregation/join.

file: pkg/util/chunk ↗ | tags: #columnar-chunk #vectorized #spill-to-disk #encoding #memory-arena #zero-copy

Expression evaluation framework with generated vectorized implementations for SIMD. 100+ builtin functions (math, string, time, JSON, regex, encryption, bit, control, cast, comparison). Code generator produces type-specialized kernels. Constant folding/propagation. Chunk-based execution. DistSQL pushdown support.

file: pkg/expression ↗ | tags: #vectorized-execution #code-generation #simd #builtin-functions #constant-folding #type-inference

Cost-based optimizer with dual engines: traditional rule-based (RBO) and Cascades framework. Features: plan cache (instance/global), parameterized plans, CBO with cardinality estimation (histograms, CMS, FM-sketch), join reorder (DP/greedy), predicate pushdown, partition pruning, MPP enforcement, index merge, lateral join, CTE optimization, plan replay capture.

file: pkg/planner/core ↗ | tags: #cascades-optimizer #cbo #plan-cache #cost-model #rule-based #mpp-planning #partition-pruning

Online DDL execution with job-based architecture: SQL → Job → Owner schedules → Workers execute steps (meta change → reorg → public). Distributed backfill via DXF for add-index. Schema versioning with etcd-based sync. Multi-schema change support. Pause/resume. Fast path for metadata-only changes. Foreign key, partition, TTL, generated column support.

file: pkg/ddl ↗ | tags: #online-ddl #job-based #distributed-backfill #schema-versioning #owner-election #reorg #checkpoint

Auto-analyze priority queue with sophisticated priority calculation: considers table size, change rate, time since last analyze, partition type. Heap-based with dynamic/static partitioned table jobs. DDL-aware queue maintenance. Calculator analysis test with golden file validation across 1K-100M row scenarios.

file: pkg/statistics/handle/autoanalyze/priorityqueue ↗ | tags: #auto-analyze #priority-queue #heap #dynamic-partition #statistics-freshness #change-rate

Complete collation support: Unicode 9.0.0 (uca0900_ai_ci), Unicode 4.0.0, GBK, GB18030, binary, pinyin. Generated weight tables from UCA allkeys.txt. Code generator produces optimized comparison functions. Supports CI/AI variants. Used in sorting, comparison, indexing.

file: pkg/util/collate ↗ | tags: #collation #unicode-9.0 #gbk #gb18030 #generated-code #weight-tables #pinyin

Global sort engine for TB-scale data import: encodes SQL rows to KV pairs, sorts via external merge sort (multi-way merge, spill management), detects duplicates across engines, computes checksums, writes SST files for TiKV ingestion. Merge v2 with improved memory management.

file: pkg/ingestor/globalsort ↗ | tags: #global-sort #external-merge-sort #kv-encoding #duplicate-detection #checksum #disk-spill

External sorting library: multi-way merge with priority queue, disk-based sorter with configurable buffer, parallel sort workers with spill helper, Top-N optimization with chunk heap, sort spill test coverage. Used by global sort, hash join spill, window functions.

file: pkg/util/extsort ↗ | tags: #external-sort #multi-way-merge #disk-sorter #parallel-sort #top-n #spill-management

Memory arena allocator for reduced GC pressure: bump-pointer allocation from large chunks, thread-local caches, automatic chunk management, benchmark showing significant GC reduction. Used in chunk processing, expression evaluation, sort/join operators.

file: pkg/util/arena ↗ | tags: #memory-arena #bump-allocator #reduced-gc #chunk-allocation #thread-local

Multi-version map for MVCC: FNV hash, per-key version chains, snapshot isolation reads, concurrent writes with lock striping, background GC of old versions, memory usage tracking. Used in transaction layer for versioned key-value storage.

file: pkg/util/mvmap ↗ | tags: #mvcc-map #multi-version #concurrent #fnv-hash #snapshot-isolation #garbage-collection

Parquet reader/writer with Apache Arrow: Spark legacy datetime/decimal rebase handling, schema builder with type mapping, column buffers for efficient encoding/decoding, writer behavior tests, test files from Hive/Aurora. Used by Lightning for Parquet import.

file: pkg/dumpformat/parquetfile ↗ | tags: #parquet #arrow #spark-compatibility #schema-evolution #decimal-rebase #columnar
Last analyzed: 2026-06-30 10:06:11.133818
Next check: 2026-09-28 12:10:37.533655
$ submit: