Terminology
- VEB (VillageSQL Extension Bundle) - The
.vebfile format, a tar archive containing manifest, library, and metadata - VEF (VillageSQL Extension Framework) - The SDK and C++ API for authoring extensions
- VDF (Village Defined Function) - Functions registered through the VEF SDK using
VEF_GENERATE_ENTRY_POINTS() - UDF (User-Defined Function) - Traditional MySQL functions registered via
CREATE FUNCTION ... SONAME(legacy approach, still supported)
VEB File Format
VillageSQL extensions are distributed as.veb (VillageSQL Extension Bundle) files - tar archives containing:
manifest.json Schema
- name: Must match extension name used in SQL (lowercase_with_underscores)
- version: Semantic version (MAJOR.MINOR.PATCH)
- description, author, license: Optional metadata
Extension Lifecycle
Installation Flow
The
vef_dir system variable points to the directory containing .veb files, despite the naming difference between VEB (file format) and VEF (SDK framework).Uninstallation Flow
villagesql.custom_columns has active usage.
Expansion Directory Structure
VillageSQL expands .veb files to support multiple versions:- Test new versions without overwriting
- Enable rollback
- Prevent “same version, different code”
Victionary Caching Layer
VictionaryClient maintains in-memory caches of system metadata for O(log n) lookups.Cached Tables
Cache Operations
| Operation | Locking | Performance |
|---|---|---|
| Read (resolve type) | Read lock | O(log n) map lookup |
| Write (install extension) | Write lock | O(log n) insert + disk I/O |
| Server startup | N/A | Full table scan into memory |
Custom Type System
Type Resolution
Implementation Types
Custom types map to MySQL storage types:| Custom Type | MySQL Implementation | Bytes |
|---|---|---|
| COMPLEX | MYSQL_TYPE_VARCHAR | 16 |
| UUID | MYSQL_TYPE_VARCHAR | 16 |
| INET6 | MYSQL_TYPE_VARCHAR | 16 |
| JSON_SCHEMA | MYSQL_TYPE_BLOB | Variable |
Concurrency & Transaction Behavior
Thread Safety Model
Extension functions are called in a per-row execution model:- Isolated per-row execution: Each function call gets its own result buffer (thread-safe by design)
- Prerun/Postrun hooks: Per-statement setup/cleanup, called once per SQL statement
- No guaranteed isolation: Multiple connections may call your functions concurrently
- Best practice: Avoid global state; use function parameters and return values
Transaction Behavior
Extension functions should follow these best practices:- Design functions to be stateless when possible
- Avoid persistent side effects (file writes, external API calls) in functions
- If using prerun/postrun state, handle cleanup appropriately
Performance Considerations
VDF Call Overhead
| Operation | Overhead |
|---|---|
| Function pointer dereference | ~1ns |
| Argument marshaling | ~10ns |
| Result copying | ~10ns |
Custom Type Performance
Security & Debugging
Security Model
Security Model
Trust model: Extensions run with full server privileges.
- No sandboxing or permission system
- Extensions can read any file, access network, execute code
- Trust implications: Only install extensions from trusted sources
villagesql_extension_installer user (context switch).Debugging Extensions
Debugging Extensions
Enable verbose logging:GDB debugging:Check dependencies:Common errors:
- Undefined symbol: Check
extern "C"linkage - Cannot open shared object: Check library dependencies
- Crash on UDF call: Check NULL pointer handling
Schema Validation
On server startup, SchemaManager validates system table schemas:- Missing table → Create from villagesql_schema.sql
- Wrong schema → Error and refuse to start
- Version mismatch → Run upgrade scripts

