Extraction Methods Guide
Quick reference for understanding and choosing between the four extraction methods supported by rust-sql-extractor.
The Four Methods
1. CDC (Change Data Capture) — Premium Incremental
Best for: OLTP systems with high volume transactions and comprehensive audit requirements
How it works: - SQL Server captures every INSERT, UPDATE, DELETE automatically - Stores changes in shadow table with operation type and before/after values - Extraction queries shadow table for changes since last LSN (Log Sequence Number)
Pros: - ✅ Complete change history (operation type, before/after values) - ✅ Delete tracking included - ✅ Minimal load on source table (no full scans) - ✅ Native SQL Server feature
Cons: - ❌ Requires explicit setup (DBA must enable) - ❌ Consumes disk space (shadow tables) - ❌ LSN values purged after retention window
When to use: - Tables already have CDC enabled - Audit trail required - High-volume transactional tables - Delete tracking essential
2. Change Tracking (CT) — Lightweight Incremental
Best for: Moderate-velocity tables without full audit needs
How it works: - SQL Server tracks which rows changed and version number - Doesn't store full row copies—just PK + version - Application joins tracked rows to get current data
Pros: - ✅ Lightweight (less storage than CDC) - ✅ Delete tracking included - ✅ Works on Standard/Express editions - ✅ Simple to understand
Cons: - ⚠️ No before/after values - ⚠️ Schema changes disable tracking - ❌ Versions purged after retention
When to use: - Don't need before/after values - Lightweight footprint required - Standard/Express SQL Server editions - Moderate change velocity
3. Watermark — DateTime-based Incremental
Best for: Tables with ModifiedDate/UpdatedAt that can't use CDC/CT
How it works:
- Queries rows where ModifiedDate > last_extraction_timestamp
- Auto-detects watermark column based on naming patterns
- Requires indexed datetime column
Pros: - ✅ Works everywhere (any database, any edition) - ✅ Simple query logic - ✅ Low overhead - ✅ Portable across databases
Cons: - ⚠️ DateTime precision issues (nanoseconds vs milliseconds) - ❌ Delete tracking not possible - ❌ Requires ModifiedDate column - ❌ Can't distinguish INSERT from UPDATE
When to use: - No CDC/CT enabled - ModifiedDate column already exists - Delete tracking not needed - Moving to different database
⚠️ Datetime Precision Fix (Important!): Previous versions failed with error:
Conversion failed when converting date and/or time from character string
WHERE [ModifiedDate] > '2008-03-11 10:32:17.973333333' ← Too many decimals!
Fix: Watermark values are now truncated to 3 decimal places (milliseconds) to match SQL Server's datetime type limit.
4. Full Extract — Complete Table Snapshot
Best for: Initial loads and recovery scenarios
How it works:
- Reads entire table: SELECT * FROM [schema].[table]
- Writes all rows to Delta Lake
Pros: - ✅ Guaranteed complete - ✅ Works everywhere - ✅ Simple
Cons: - ❌ Slow for large tables - ❌ High resource usage - ❌ Can't track deletes alone - ❌ Data duplication on repeat
When to use: - Initial load (always) - State reset (clears incremental state) - Fallback (when watermark has no state) - Recovery (data corruption/missing changes)
Row Hashing (Hash-based Merge)
When Enable Row Hashing is turned on for a Full Extract table:
- Adds a _hash column (SHA256) to each row
- Uses MergeDeltaWriter to upsert based on primary key + hash comparison
- Only rows with changed hash values are updated
⚠️ Requirements for Row Hashing: 1. Primary Key Required — Table must have primary key columns defined 2. Full Extract Strategy — Works only with Full Extract (not CDC/CT/Watermark)
Why Primary Key is Required: - MergeDeltaWriter uses PK columns to identify which rows to update/insert - Without PK, the merge operation cannot determine row identity - UI will disable the hashing toggle if no primary key exists
How _hash is Computed
- Algorithm: Deterministic SHA-256 encoded as 64 lowercase hexadecimal characters in the
_hashcolumn. - Column ordering: Columns are sorted lexicographically by name so query column order changes do not invalidate hashes.
- Excluded columns: Internal/metadata columns starting with
__(e.g., CDC__$*),_hash, andSYS_CHANGE_OPERATIONare skipped. - Collision-resistant encoding: Each cell is hashed as
<column_name>=<type_tag><value>\x1f(unit separator0x1F) using explicit runtime type tags:N(Null),B(Bool, 1 byte),I(Int64, little-endian bytes),F(Float64, little-endian bytes),D(Decimal string),S(UTF-8 string), andX(raw bytes). This guaranteesInt64(1),Str("1"),Null,"", and shifted column boundaries never collide. - ADBC note: When row hashing is enabled on a table, extraction uses the typed-row hashing path rather than ADBC's zero-JSON Arrow
RecordBatchfast path.
State Reset Behavior
When you reset extraction state:
CDC/CT Tables (FIXED)
- Before fix: State cleared but extraction still tried CDC → missed changes
- After fix: Triggers automatic full extract to re-establish baseline
- Next run: Resumes CDC/CT incrementally with new state
Watermark Tables
- Behavior: Watermark value cleared → falls back to full
- Next run: Re-extracts full table, establishes new watermark
- Note: Works correctly without special handling
Example:
Day 1: CDC extract (state saved with LSN=0x1000)
Day 6: reset_extraction_state()
Day 7: System detects state=None → forces full extract
Day 8: Extracts CDC changes from new LSN baseline
Decision Tree
Is CDC enabled on this table?
├─ YES → Use CDC (best for audit/deletes/performance)
│
└─ NO → Is Change Tracking enabled?
├─ YES → Use Change Tracking (good balance)
│
└─ NO → Is there a ModifiedDate/UpdatedAt column?
├─ YES → Use Watermark (simple, portable)
│
└─ NO → Use Full Extract (only option)
Performance Comparison
| Aspect | CDC | CT | Watermark | Full |
|---|---|---|---|---|
| First run | Full | Full | Full | Full |
| Incremental time | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ | ⭐ |
| Network traffic | Low | Low | Medium | High |
| Source load | Minimal | Minimal | Moderate | Heavy |
| Delete tracking | ✅ | ✅ | ❌ | ⚠️ |
| Setup required | ✅ | ✅ | ❌ | ❌ |
Common Issues & Fixes
Issue: Watermark query fails with datetime error
Error: Conversion failed when converting date and/or time
Cause: JSON datetime has too many decimal places
Fix: ✅ Now automatic—truncates to 3 decimals
Issue: Reset doesn't seem to work for CDC tables
Error: Next run still misses data, or extracts nothing Cause: State cleared but extraction tried incremental from min LSN Fix: ✅ Now automatically triggers full extract on reset
Issue: Watermark skips rows at high update velocity
Cause: Multiple rows get same timestamp Fix: Increase batch size, or add secondary ordering column
For More Details
- EXTRACTION_STRATEGIES.md — In-depth comparison with code examples
- CATALOG.md — How to configure extraction per table