Data Query, Update and Delete
This comprehensive guide covers all fundamental data operations in Tacnode. Learn how to query, modify, and manage your data efficiently using SQL commands optimized for Tacnode's distributed architecture.
Quick Reference
Operation | Purpose | Key Features |
---|---|---|
SELECT | Query and retrieve data | Filtering, joins, aggregations, CTEs |
DELETE | Remove records | Conditional deletion, multi-table operations |
UPDATE | Modify existing data | Single/batch updates, computed values |
MERGE | Upsert operations | INSERT + UPDATE in one command |
TRUNCATE | Remove all records | Fast table clearing |
VIEW | Virtual tables | Reusable query logic |
SELECT
The SELECT
statement is your primary tool for data retrieval and analysis. It supports everything from simple filtering to complex analytical queries.
Basic Syntax:
For complete syntax reference, see SELECT documentation.
Working with Sample Data
Throughout this guide, we'll use this sample table:
Basic Queries
Filter by condition:
Sort and limit results:
Advanced Querying
Aggregations and grouping:
Subqueries
Use subqueries to create complex filtering conditions:
Common Table Expressions (CTE)
CTEs make complex queries more readable by breaking them into logical components:
DELETE
Remove data from tables with precise control over which records to delete.
Basic Syntax:
For complete syntax reference, see DELETE documentation.
Simple Deletions
Multi-table Deletions
Use DELETE USING
for complex deletions involving multiple tables:
Batch Deletions
For large datasets, consider batch deletions to avoid long-running transactions:
Important: Tacnode uses MVCC (Multi-Version Concurrency Control). Deleted data isn't immediately removed from disk but cleaned up asynchronously. This temporarily increases storage usage until compaction completes.
UPDATE
Modify existing records in your tables efficiently.
Basic Syntax:
For complete syntax reference, see UPDATE documentation.
Simple Updates
Computed Updates
Bulk Updates
Important: Like DELETE, UPDATE operations use MVCC. Old versions remain on disk temporarily until asynchronous compaction removes them.
MERGE
Combine INSERT and UPDATE operations in a single, atomic command. Perfect for data synchronization and upsert scenarios.
Basic Syntax:
Data Synchronization
ETL Operations
For complete syntax reference, see MERGE documentation.
TRUNCATE
Quickly remove all data from a table. Much faster than DELETE
for removing all records.
Basic Syntax:
Fast Table Clearing
When to Use TRUNCATE vs DELETE
Operation | Use When | Performance | Transaction Log |
---|---|---|---|
TRUNCATE | Removing all data | Very fast | Minimal logging |
DELETE | Conditional removal | Slower | Full logging |
Key Differences:
TRUNCATE
resets identity sequencesTRUNCATE
cannot have a WHERE clauseTRUNCATE
is faster but less flexibleDELETE
allows row-by-row processing
For complete syntax reference, see TRUNCATE documentation.
VIEW
Create virtual tables that store queries, not data. Views provide data abstraction, security, and code reusability.
Basic Syntax:
Simple Views
Complex Views
View Management
Security with Views
Views can provide row-level security and column filtering:
For complete syntax reference, see CREATE VIEW, ALTER VIEW, and DROP VIEW documentation.
Performance Tips
Query Optimization
-
Use indexes effectively:
-
Limit result sets:
-
Use EXPLAIN to analyze queries:
Transaction Management
Best Practices
- Always use WHERE clauses with UPDATE and DELETE to avoid accidental data modification
- Test queries on small datasets before running on production data
- Use transactions for related operations that must succeed or fail together
- Monitor query performance with EXPLAIN and adjust indexes as needed
- Use CTEs to break complex queries into readable parts
- Consider MERGE for upsert operations instead of separate INSERT/UPDATE logic
- Use views to encapsulate complex business logic and provide security layers
- Batch large operations to avoid long-running transactions and locks
This comprehensive guide provides the foundation for all data operations in Tacnode. Each operation builds upon these fundamentals to support complex data management scenarios in production environments.