Bird
0
0

Consider this SQL snippet:

medium📝 query result Q5 of 15
PostgreSQL - Advanced Features
Consider this SQL snippet:
SELECT * FROM foreign_table LIMIT 5;

Assuming foreign_table is a foreign table via postgres_fdw connected to a remote PostgreSQL server, what happens when this query runs?
APostgreSQL fetches only 5 rows from the remote table and returns them
BPostgreSQL fetches all rows from remote table then limits to 5 locally
CQuery fails because LIMIT is not supported on foreign tables
DPostgreSQL creates a local copy of the table with 5 rows
Step-by-Step Solution
Solution:
  1. Step 1: Understand postgres_fdw query pushdown

    postgres_fdw pushes down LIMIT to remote server to optimize data transfer.
  2. Step 2: Analyze query behavior

    Only 5 rows are fetched from remote server, not all rows then limited locally.
  3. Final Answer:

    PostgreSQL fetches only 5 rows from the remote table and returns them -> Option A
  4. Quick Check:

    FDW pushes LIMIT to remote = PostgreSQL fetches only 5 rows from the remote table and returns them [OK]
Quick Trick: FDW pushes LIMIT to remote server to reduce data [OK]
Common Mistakes:
  • Assuming all rows fetched then limited locally
  • Thinking LIMIT is unsupported on foreign tables
  • Believing a local copy is created automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes