#821

Rewrite a year filter so the index actually fires

The original query expresses the year filter as «extract the year from created_at and compare with 2024». The trouble: the column is wrapped in a function, the planner can't use the created_at index, and falls back to a full table scan. Rewrite the filter as a date range so the planner can spot the b-tree index and pick it up (this form of condition is called «sargable»). Return the id, total, and creation date of orders placed in 2024, sort by id.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.

idtotalcreated_at
11002024-01-05T00:00:00+00:00
21502024-01-12T00:00:00+00:00
32002024-01-20T00:00:00+00:00

Your query result will appear here