SQL Reference
AVA Database® implements a comprehensive SQL interface that combines ANSI SQL compatibility with powerful extensions designed for analytical workloads and high-performance data processing.
ANSI SQL Compatibility
AVA DB provides extensive support for ANSI SQL standards, allowing you to use familiar SQL syntax and semantics. The database engine understands standard SQL commands and follows SQL conventions for query execution, data manipulation, and schema management.
Supported ANSI SQL Features
- Data Query Language (DQL) - Full SELECT statement support with WHERE, GROUP BY, HAVING, ORDER BY, TOP, BOTTOM, and LIMIT clauses
- Data Manipulation Language (DML) - INSERT, UPDATE, DELETE operations
- Data Definition Language (DDL) - CREATE TABLE, ALTER TABLE, DROP TABLE statements
- Joins - INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN
- Subqueries - Nested queries in SELECT, FROM, and WHERE clauses
- Aggregation - COUNT, SUM, AVG, MIN, MAX, and more
- Set Operations - UNION, INTERSECT, EXCEPT
- Window Functions - OVER, PARTITION BY, ROW_NUMBER, RANK
Standard SQL Example
-- Standard ANSI SQL query
SELECT
department,
COUNT(*) as employee_count,
AVG(salary) as avg_salary
FROM employees
WHERE hire_date >= '2023-01-01'
GROUP BY department
HAVING COUNT(*) > 5
ORDER BY avg_salary DESC;
Core SQL Statements
AVA DB supports all essential SQL statements for data querying and manipulation:
| Statement | Category | Description |
|---|---|---|
SELECT |
DQL | Query data from tables with filtering, grouping, and aggregation |
INSERT |
DML | Insert new rows into a table |
UPDATE |
DML | Modify existing rows in a table |
DELETE |
DML | Remove rows from a table |
CREATE TABLE |
DDL | Define a new table with columns and data types |
ALTER TABLE |
DDL | Modify table structure (add/drop columns, rename, etc.) |
DROP TABLE |
DDL | Remove a table and its data from the database |
Extended SQL Capabilities
Beyond ANSI SQL, AVA DB provides powerful extensions for analytical processing and advanced data operations:
Analytical Extensions
| Extension | Description |
|---|---|
REGRESS |
Linear regression analysis directly in SQL for statistical modeling |
TRANSPOSE |
Pivot and unpivot operations for data reshaping |
COMPRESS |
Apply compression to table columns for storage optimization |
ODBC |
ODBC connectivity for external data sources |
Regression Example
-- Linear regression analysis
REGRESS sales_amount ON advertising_spend, seasonality
FROM quarterly_sales
WHERE year >= 2020;
Transpose Example
-- Pivot data from rows to columns
TRANSPOSE revenue
FROM monthly_data
KEY BY product_id
GROUP BY year, quarter;
System Commands
AVA DB provides system commands that start with a dot (.) for database management, metadata access, and utility operations. These commands are not part of standard SQL but provide essential functionality for database administration and data management.
Meta-Information Commands
| Command | Syntax | Description |
|---|---|---|
.tables |
.tables |
List all tables in the current database |
.schema |
.schema [table_name] |
Display the schema (structure) of a specified table including columns, types, and constraints |
Data Import/Export Commands
| Command | Syntax | Description |
|---|---|---|
.load |
.load "file.csv" as table_name |
Load data from a CSV or text file into a table |
.save |
.save table_name "file.csv" |
Export table data to a CSV or text file |
Storage Management Commands
| Command | Syntax | Description |
|---|---|---|
.compress |
.compress table_name by method |
Apply compression to table for reduced storage footprint |
.decompress |
.decompress table_name |
Remove compression from a table |
.sort |
.sort table_name by column_name |
Physically sort table data by specified column(s) for query optimization |
Connection and Session Commands
| Command | Syntax | Description |
|---|---|---|
.odbc |
.odbc connect ... |
Establish ODBC connection to external data sources |
.sessions |
.sessions |
Display active client sessions and connections |
Multi-Threading Commands
| Command | Syntax | Description |
|---|---|---|
.jobs |
.jobs |
List all running background jobs and their status |
.kill_job |
.kill_job [job_id] |
Terminate a specific background job |
System Command Examples
-- List all tables in database
.tables
-- Show schema for specific table
.schema employees
-- Load CSV data into table
.load "data/employees.csv" as employees
-- Export table to CSV
.save employees "output/employees_backup.csv"
-- Compress table for storage efficiency
.compress sales_data by lz4
-- Sort table physically by date column
.sort transactions by transaction_date
-- View active sessions
.sessions
-- List background jobs
.jobs
Performance Features
AVA DB's SQL implementation is optimized for analytical workloads with several high-performance features:
- Columnar Storage - Data stored column-wise for efficient analytical queries
- Vectorized Execution - SIMD operations (AVX-512) for processing multiple rows simultaneously
- Parallel Query Execution - Multi-threaded query processing for large datasets
- Intelligent Compression - Automatic compression selection based on data characteristics
- Dictionary Encoding - Efficient encoding for string columns
- Predicate Pushdown - Early filtering to reduce data movement
- Late Materialization - Delayed column access until required
SQL Execution Model
AVA DB processes SQL queries through a sophisticated execution pipeline:
- Parsing - SQL text is parsed into an Abstract Syntax Tree (AST)
- Analysis - Semantic validation and type checking
- Optimization - Query rewriting and execution plan generation
- Vectorization - Operations compiled to SIMD instructions where possible
- Execution - Parallel execution across multiple threads
- Result Materialization - Final results assembled and returned
SQL Query
↓
Parser (AST Generation)
↓
Semantic Analyzer
↓
Query Optimizer
↓
Vectorization Layer (AVX-512)
↓
Parallel Execution Engine
↓
Result Set
Key Differences from Standard SQL
While AVA DB maintains high ANSI SQL compatibility, there are some intentional differences designed for performance and analytical use cases:
| Feature | Standard SQL | AVA DB |
|---|---|---|
| Primary Focus | Transactional (OLTP) | Analytical (OLAP) |
| Storage Model | Row-oriented | Column-oriented |
| VARCHAR Max Length | Implementation dependent | 16,384 bytes |
| System Commands | Vendor-specific | Dot-prefixed (e.g., .tables) |
| Compression | Optional, external | Built-in, SQL-accessible |
| Analytics Functions | Limited | Extended (REGRESS, TRANSPOSE) |
Next Steps
Explore the detailed documentation for specific SQL features:
- Data Types Reference - Complete guide to AVA DB data types
- SQL Statements - Detailed syntax for each SQL command
- Functions Reference - Built-in functions and aggregations
- System Commands - In-depth guide to dot commands
- Python API - Execute SQL from Python applications