Bird
0
0

Given the table definition:

medium📝 query result Q13 of 15
PostgreSQL - Table Partitioning
Given the table definition:
CREATE TABLE users (id INT, name TEXT) PARTITION BY HASH (id);
CREATE TABLE users_p0 PARTITION OF users FOR VALUES WITH (MODULUS 4, REMAINDER 0);
CREATE TABLE users_p1 PARTITION OF users FOR VALUES WITH (MODULUS 4, REMAINDER 1);
CREATE TABLE users_p2 PARTITION OF users FOR VALUES WITH (MODULUS 4, REMAINDER 2);
CREATE TABLE users_p3 PARTITION OF users FOR VALUES WITH (MODULUS 4, REMAINDER 3);

Which partition will the row with id = 7 be stored in?
Ausers_p3
Busers_p1
Cusers_p2
Dusers_p0
Step-by-Step Solution
Solution:
  1. Step 1: Calculate hash partition remainder

    Partition is chosen by (hash(id) % modulus). Assuming hash(id) = id for simplicity, 7 % 4 = 3.
  2. Step 2: Match remainder to partition

    Remainder 3 corresponds to partition users_p3.
  3. Final Answer:

    users_p3 -> Option A
  4. Quick Check:

    7 % 4 = 3 -> users_p3 [OK]
Quick Trick: Compute id % modulus to find partition remainder [OK]
Common Mistakes:
  • Confusing remainder with modulus
  • Using id directly without modulo
  • Mixing partition numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes