Skip to main content

Tablesample

Save 90-99% on query costs during development by sampling a percentage of your data.


The Problem

Running a query 20 times during development at $0.63 each = $12.50.

The Solution

Sample 1% of your data to test query logic at a fraction of the cost.

Same query logic, 99% less cost.


How to Enable

Option 1: Config Panel

Set the sample percentage in the Tablesample field in the config panel. The value automatically injects a directive into your query.

Tablesample in Config Panel

Option 2: Comment Directive

Add a comment directive directly in your SQL:

-- querylab:tablesample=1

SELECT * FROM orders WHERE order_date >= '2024-01-01'
-- Cost: $0.006 instead of $0.63

Directive Syntax

-- querylab:tablesample=<percentage>
-- querylab:tablesample-threshold=<size>

tablesample

Sets the sample percentage (0.01-100).

PercentageUse Case
0.1Very large tables (billions of rows)
1Standard development
10Validation testing
100Production (same as no directive)

tablesample-threshold

Only sample tables larger than this size. Smaller tables are queried in full.

-- querylab:tablesample=1
-- querylab:tablesample-threshold=10gb

SELECT * FROM huge_table -- Sampled (>10GB)
JOIN small_lookup -- Not sampled (<10GB)
SizeExample
100mb100 megabytes
1gb1 gigabyte
10gb10 gigabytes
1tb1 terabyte

Important Notes

  • Results are sampled - counts and aggregations are approximate
  • Non-deterministic - different rows each run
  • Small tables may return empty results (use higher %)
  • Remove directive for production

Workflow

  1. 1% - Develop and test query logic
  2. 10% - Validate results look correct
  3. Remove directive - Run on full data

Insights Panel

When active, the panel shows:

Development Mode: Active
Sample Size: 1%
Dev Cost: $0.006
Prod Cost: $0.63
Savings: 99%