Choosing Returned Columns for an Operational Query

The columns a query returns can affect data transfer, object construction, and which access paths are useful.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a title index
  2. Measure the actual behavior
  3. Measure what is fetched and what is transmitted
  4. Verify that fewer fields serve real callers

Trace a title index

A directory may use only ID and title. Returning long article bodies transfers data the directory never renders. Explicit select lists make the intended shape visible.

Measure the actual behavior

Some indexes can supply requested fields under their conditions. A narrower result alone does not prove index-only execution. See covering indexes for the additional requirements.[1]

Measure what is fetched and what is transmitted

A summary endpoint can need ID and state for one hundred jobs. Selecting a large retained diagnostic payload for every job increases result bytes even if the display ignores it. A narrower projection can reduce transfer and decoding work. See choosing explicit columns.

Required result per row: ID and state
Optional large payload omitted from query result
Compare transferred bytes and endpoint elapsed time

Verify that fewer fields serve real callers

A serializer may implicitly depend on a field that was removed. Inspect its contract and integration tests. Database work also depends on access paths, so measure plan and user-facing latency separately.

References

  1. PostgreSQL Global Development Group, Concurrency Control ↩