Challenge - 5 Problems
TABLESAMPLE Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What does this TABLESAMPLE query return?
Consider a table employees with 1000 rows. What is the expected output of this query?
SELECT * FROM employees TABLESAMPLE SYSTEM (10);
PostgreSQL
SELECT * FROM employees TABLESAMPLE SYSTEM (10);
Attempts:
2 left
💡 Hint
SYSTEM sampling method picks a percentage of rows approximately.
✗ Incorrect
The SYSTEM method in TABLESAMPLE picks approximately the given percentage of rows randomly. So SYSTEM (10) means about 10% of rows.
📝 Syntax
intermediate2:00remaining
Which option is the correct syntax for TABLESAMPLE in PostgreSQL?
Identify the valid TABLESAMPLE syntax to sample 5% of rows from a table named
orders.Attempts:
2 left
💡 Hint
The sampling method name comes right after TABLESAMPLE, followed by the percentage in parentheses.
✗ Incorrect
The correct syntax is TABLESAMPLE method_name (percentage). Option C follows this format correctly.
❓ optimization
advanced2:00remaining
Which TABLESAMPLE method is more efficient for large tables and why?
You want to sample 1% of rows from a very large table. Which TABLESAMPLE method is generally more efficient and why?
Attempts:
2 left
💡 Hint
Think about how sampling by blocks vs rows affects performance.
✗ Incorrect
SYSTEM samples whole data blocks, which is faster on large tables but less precise. BERNOULLI checks each row, which is slower.
🧠 Conceptual
advanced2:00remaining
Why might TABLESAMPLE SYSTEM not return exactly the requested percentage of rows?
Explain why TABLESAMPLE SYSTEM (10) might return more or fewer than exactly 10% of rows.
Attempts:
2 left
💡 Hint
Think about how data is stored physically in blocks.
✗ Incorrect
SYSTEM samples whole blocks, so if blocks have different numbers of rows, the total rows sampled can vary from the exact percentage.
🔧 Debug
expert2:00remaining
What error does this query raise and why?
Given the query:
What error will PostgreSQL raise and why?
SELECT * FROM sales TABLESAMPLE BERNOULLI (105);
What error will PostgreSQL raise and why?
PostgreSQL
SELECT * FROM sales TABLESAMPLE BERNOULLI (105);
Attempts:
2 left
💡 Hint
Sampling percentage must be a valid percentage value.
✗ Incorrect
PostgreSQL requires the sampling percentage to be between 0 and 100 inclusive. 105 is invalid and causes an error.