.veb file. When you run INSTALL EXTENSION, VillageSQL
loads your library, calls your registration code, and makes your functions
immediately available as SQL — callable from any query as if they were built into
the server. No server restart required. The rest of this page explains how each
step of that process works.
Terminology
- VEB (VillageSQL Extension Bundle) - The
.vebfile format, a tar archive containing manifest, library, and metadata - VEF (VillageSQL Extension Framework) - The C++ and Rust SDKs for authoring extensions
- VDF (VillageSQL Defined Function) - Functions registered through VEF — via
VEF_GENERATE_ENTRY_POINTS()in C++ or theextension!macro in Rust
VDF Function Lookup
VDFs support both qualified and unqualified function calls:- System functions (built-in MySQL)
- UDFs (traditional MySQL user-defined functions via
CREATE FUNCTION ... SONAME) - VDFs (extension functions) - only if exactly one function with that name exists
- Stored functions (created with
CREATE FUNCTION)
extension_name.function_name()) must be used.
Performance: For hot code paths, use qualified calls (extension_name.function_name()) to skip the resolution chain and directly invoke the extension function.
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
.so is unloaded.
Symbol Isolation: Extensions are loaded with RTLD_LOCAL flag, ensuring symbols from one extension don’t conflict with symbols from other extensions. This prevents naming collisions when multiple extensions use common library names or function names.
The
veb_dir system variable points to the directory where .veb extension files are stored.Uninstallation Flow
Expansion Directory Structure
VillageSQL expands .veb files into the MySQL data directory 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.Cache Operations
Cache invalidation: Automatic during DDL operations (INSTALL/UNINSTALL EXTENSION).
Memory overhead: ~100 bytes per entry.
Custom Type System
Type Resolution
Implementation Types
Custom types map to MySQL storage types: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
Optimization: Use prerun hooks to cache expensive per-statement setup instead of repeating work per-row.Custom Type Performance
Security & Debugging
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 library dependencies with
ldd(Linux) orotool -L(macOS) - Cannot open shared object: Check library dependencies are present and correctly linked
- Crash on VDF call: Check NULL pointer handling
Next Steps
Create Extension
Build your first extension
System Reference
System tables and views
Examples
Study vsql_complex implementation
Managing Extensions
Monitor and troubleshoot

