AGENTS.md
AGENTS.mdAGENTS.mdroot
Quality
96/100
Scores the file, not the repository.Length
1,613 words
42 headings · 11 code blocksRepository
40k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# AGENTS.md23This file provides guidance to coding agents when working with code in this repository.45## Overview67DuckDB is a high-performance analytical database system designed to be fast, reliable, portable, and easy to use. It is an analytical database management system with a rich SQL dialect, vectorized execution engine, and columnar storage format.89## Build Commands1011### Basic Build12```bash13make debug # Builds debug version with sanitizers and assertions14make reldebug # Builds optimized release version with debug symbols15FORCE_DEBUG=1 make relassert # Builds optimized version with sanitizers and assertions16```1718## Testing1920### Running Tests21```bash22build/reldebug/test/unittest # Fast unit tests23```2425### Running Specific Tests26```bash27# Run specific test file28build/reldebug/test/unittest test/sql/order/test_limit.test2930# Run all tests including slow tests31build/reldebug/test/unittest "*"32```3334It is recommended to use `make reldebug` and `build/reldebug/test/unittest` unless a good reason exists to use the debug build - the debug build is much slower than the reldebug build.3536### Test File Format37Tests use the sqllogictest format (`.test` files). Example structure:38```sql39# name: test/sql/order/test_limit.test40# description: Test LIMIT keyword41# group: [order]4243statement ok44CREATE TABLE test (a INTEGER, b INTEGER);4546query I47SELECT a FROM test LIMIT 148----49115051statement error52SELECT a FROM test LIMIT a53----54<REGEX>:Binder Error:.*not found.*55```5657Test directives:58- `statement ok` - Statement should succeed59- `statement error` - Statement should fail60- `query I` - Query returning INTEGER column61- `query II` - Query returning two columns62- `----` - Separates query from expected results63- `<REGEX>:` - Expected error message pattern64- `require-env VAR` - Test requires environment variable6566Slow tests should use `.test_slow` extension instead of `.test`.6768## Code Formatting6970```bash71make format-fix # Format all code (clang-format + black)72make generate-files # Generate files + format all code73```7475Ensure you run formatting before committing.7677## Extensive Testing / Making CI Work7879Below is a set of tests that should be run in order to make sure a changeset passes extensive tests in CI. If the user is asking you to fix CI make sure that the below commands succeed.8081```bash82make allunit83FORCE_DEBUG=1 FORCE_ASSERT=1 make reldebug && build/reldebug/test/unittest84make test_configs85make test_vector86```878889## Architecture9091### Query Execution Pipeline9293```94SQL String95 ↓96[PARSER] - Uses a PEG parser to parse SQL into AST97 ↓98SQLStatement tree (ParsedExpression, TableRef objects)99 ↓100[PLANNER/BINDER] - Binds symbols to catalog, creates logical plan101 ↓102Logical Plan (LogicalOperator tree with bound Expressions)103 ↓104[OPTIMIZER] - Applies rule-based and cost-based optimizations105 ↓106Optimized Logical Plan107 ↓108[PHYSICAL PLAN GENERATOR] - Converts to physical operators109 ↓110Physical Plan (PhysicalOperator tree)111 ↓112[EXECUTOR] - Executes with vectorized, parallel pipelines113 ↓114Results115```116117### Core Components118119**Parser** (`src/parser/`)120- Converts SQL strings to Abstract Syntax Tree (AST)121- Uses a PEG-based parser122- The grammar is located in `*.gram` files and generated using `scripts/build_grammar.sh`123- Outputs: `SQLStatement`, `ParsedExpression`, `TableRef` objects124- Key subdirectories: `expression/`, `statement/`, `tableref/`, `peg/`125126For more details on adding new grammar, see the README located at `src/parser/peg/README.md`.127Each new grammar rule must have a corresponding transformer rule, located at `peg/transformer`.128129**Planner** (`src/planner/`)130- Binds symbols to catalog entries and resolves types131- Creates logical query execution plan132- Key classes: `Binder`, `LogicalOperator`, bound `Expression` types133- Subdirectories: `binder/`, `expression/`, `subquery/`134135**Optimizer** (`src/optimizer/`)136- Transforms logical plans without changing semantics137- Applies predicate pushdown, join ordering, expression rewriting, etc.138- Subdirectories: `join_order/`, `statistics/`, `rule/`, `pushdown/`139140**Execution Engine** (`src/execution/`)141- Converts logical plan to physical plan and executes142- Push-based vectorized execution model143- Processes data in batches (typically 2048 rows)144- Key subdirectories: `operator/` (scan, join, filter, aggregate, etc.), `expression_executor/`145146**Storage** (`src/storage/`)147- Manages persistent data storage and buffer management148- Block-based storage with compression149- Includes WAL (Write-Ahead Log) for durability150- Subdirectories: `buffer/`, `compression/`, `checkpoint/`, `table/`151152**Catalog** (`src/catalog/`)153- Metadata management for tables, schemas, functions, types, etc.154- Single source of truth for database metadata155- Key classes: `Catalog`, `CatalogEntry`, `SchemaCatalogEntry`156157**Transaction Manager** (`src/transaction/`)158- ACID transaction management with MVCC159- Coordinates concurrent access to data160- Key files: `transaction_manager.cpp`, `undo_buffer.cpp`, `wal_write_state.cpp`161162**Parallel Execution** (`src/parallel/`)163- Multi-threaded execution with task scheduling164- Pipeline-based parallelism165- Key files: `executor.cpp`, `pipeline_executor.cpp`, `task_scheduler.cpp`166167**Functions** (`src/function/`)168- Built-in function implementations169- Types: `scalar/`, `aggregate/`, `table/`, `window/`, `pragma/`170171### Directory Structure172173```174/duckdb175├── src/ # Core C++ source code176│ ├── include/duckdb/ # Public headers177│ ├── parser/ # SQL parsing178│ ├── planner/ # Logical planning179│ ├── optimizer/ # Query optimization180│ ├── execution/ # Physical execution181│ ├── storage/ # Data storage182│ ├── catalog/ # Metadata management183│ ├── transaction/ # Transaction management184│ ├── parallel/ # Parallelization185│ ├── function/ # Built-in functions186│ ├── common/ # Shared utilities and types187│ └── main/ # Database/connection management188├── extension/ # In-tree extensions (parquet, json, icu, etc.)189├── test/ # Test framework and test cases190│ ├── sql/ # SQL regression tests (.test files)191│ └── api/ # C/C++ API tests192├── tools/ # Language bindings (pythonpkg, shell, etc.)193├── benchmark/ # Benchmark suites (TPC-H, TPC-DS, etc.)194├── scripts/ # Build and utility scripts195└── third_party/ # Third-party dependencies196```197198## Extensions199200DuckDB supports two types of extensions:201202**In-Tree Extensions** (in `extension/` directory):203- Extensions are located in-tree204- Full list in `.github/config/in_tree_extensions.cmake`205- Code can be edited directly and checked into the repository.206207**Out-of-Tree Extensions**:208- Extensions are located in a separate git repository209- Full list in `.github/config/out_of_tree_extensions.cmake`210- When changes have to be made, they have to be made in patch files stored in `.github/patches`211212Building with extensions:213```bash214# build all extensions215BUILD_ALL_EXT=1 make216# build specific extensions217DUCKDB_EXTENSIONS='json;icu' make218```219220## Key Development Patterns221222### Data Flow223- **Vectorized Processing**: Data processed in columnar batches (not row-by-row), typically 2048 rows per batch224- **Vector class**: Represents a columnar batch of data225- **ColumnBinding**: Unique identifier `(table_index, column_index)` for columns throughout planning/execution226227### Expression Types228- `ParsedExpression` - From parser, unbound229- `Expression` - Bound with type information230- `ExpressionExecutor` - Vectorized execution of expressions231232### Memory Management233- Prefer `unique_ptr<T>` for exclusive ownership234- Use `shared_ptr<T>` only when necessary235- `optional_ptr<T>` for nullable references, `reference<T>` for non-nullable references236- Never use raw pointers237238### Type System239- `LogicalType` - Abstract data type representation240- Type promotion rules in `src/function/cast_rules.cpp`241- Custom types supported via extension system242243### Common Patterns244- **Visitor Pattern**: For tree traversal (e.g., `LogicalOperatorVisitor`, `ExpressionIterator`)245- **Factory Pattern**: `Deserialize()` methods for object creation246- **Class Hierarchy**: Base classes like `*Operator`, `*Entry`, `*Expression` with typed subclasses247248## Coding Guidelines (Key Points)249250### C++ Style251- Use tabs for indentation, spaces for alignment252- Lines should not exceed 120 columns (run formatter)253- Use `[u]int(8|16|32|64)_t` instead of `int`, `long`, etc.254- Use `idx_t` instead of `size_t` for offsets/indices/counts255- Use `const` references for non-trivial objects256- Use C++11 range-based for loops when possible257- Always use braces for if statements and loops258- Never use `const_cast`259260### Comment Conventions261262Try to keep comments short. In general, comments should be one short line. Only in exceptional situations should comments be more than one short line. Code should be mostly self-descriptive and too many large comments make code harder to read and understand.263264Avoid adding comments specific to how a change was made to the code that relates to a specific issue. For example, a comment like "add +1 to fix an off-by-one error" is not relevant to understanding the code. Such comments related to specific issues that were addressed belong in a PR description or commit message, not in the code itself.265266### Naming Conventions267- **Files**: `snake_case` (e.g., `abstract_operator.cpp`)268- **Types**: `PascalCase` (e.g., `LogicalOperator`)269- **Variables**: `snake_case` (e.g., `chunk_size`)270- **Functions**: `PascalCase` (e.g., `GetChunk`)271272### Class Layout273```cpp274class MyClass {275public:276 MyClass();277 int my_public_variable;278279public:280 void MyFunction();281282private:283 void MyPrivateFunction();284285private:286 int my_private_variable;287};288```289290### Error Handling291- Use exceptions for query-terminating errors (parser error, table not found, out-of-memory, etc.)292- Use return values for errors that are recoverable during a query293- Use `D_ASSERT` for programmer errors (never triggered by user input)294- Assert liberally with clear comments295296### Testing Requirements297- Prefer sqllogictest framework (`.test` files) over C++ tests298- Test with different types (numerics, strings, nested types)299- Test unexpected/incorrect usage, not just happy path300- Slow tests should use `.test_slow` extension301- All tests must pass before submitting PR (`make allunit`)302- Aim for high code coverage303304## Navigation Tips305306### Finding Components307- Entry point: `src/main/database.cpp` (DatabaseInstance)308- Query execution coordinator: `src/main/client_context.cpp`309- SQL parsing: `src/parser/parser.cpp`310- Logical planning: `src/planner/binder/query_planner.cpp`311- Optimization orchestration: `src/optimizer/optimizer.cpp`312- Physical plan generation: `src/execution/physical_plan/physical_plan_generator.cpp`313- Execution orchestration: `src/parallel/executor.cpp`314315### Searching the Codebase316- Use `grep` or `ripgrep` for code search317- Function definitions typically in `.cpp` files318- Class declarations in `src/include/duckdb/` headers319- Test cases in `test/sql/` by functionality320321### Understanding a Feature3221. Find test cases in `test/sql/` to see usage examples3232. Trace from parser → planner → optimizer → execution3243. Look for corresponding `*Statement`, `*Operator`, `*Expression` classes3254. Check function registration in catalog326327### Modifying Generated Files328Some files are auto-generated. After modifying their sources, run:329```bash330make generate-files331```332This regenerates:333- C API bindings334- Function registration335- Settings336- Serialization code337- Storage info338- Metric enums339- Enum utilities340341## Documentation342343- Main docs: https://duckdb.org/docs/344- Development docs: https://duckdb.org/dev/345- Build guide: https://duckdb.org/docs/dev/building/overview346- Testing docs: https://duckdb.org/dev/testing347348## Important Files349350- `Makefile` - Main build configuration351- `CMakeLists.txt` - CMake configuration352- `CONTRIBUTING.md` - Contribution guidelines353- `test/README.md` - Testing documentation354- `extension/extension_config.cmake` - Extension configuration355- `scripts/format.py` - Code formatter356- `scripts/generate_*.py` - Code generation scripts357
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 67k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| OnlyTerp/prompt-cache-skillsAGENTS.md · 111 | AGENTS.md | setupbuildtestlint-format+5 | 100/100 | 3 days ago | |
| wpscanteam/wpscanAGENTS.md · 9.7k | AGENTS.md | setupbuildteststyle+6 | 100/100 | 2 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago |
