Background: I have a table consisting of roughly 14k rows running on
postgresql. I want to do this in a performance friendly way.
(1.6ms) SELECT COUNT(*) FROM “timed_assets”
(7.5ms) SELECT “timed_assets”.“id” FROM “timed_assets”
This shows me that pluck is indeed going over all the rows.
TimedAsset Load (0.7ms) SELECT “timed_assets”.* FROM “timed_assets”
ORDER BY “timed_assets”.“id” ASC LIMIT 1
Shows me the first row contains an ID of 44
(7.2ms) SELECT “timed_assets”.“id” FROM “timed_assets”
I would expect the first ID would be 44, not 5700, so I assume that
gives me an un-ordered list?
(14.4ms) SELECT “timed_assets”.“id” FROM “timed_assets” ORDER BY id
So instead, it seems I have to order the entire table first, then pluck,
and then getting the last few rows. This seems extremely inefficient
I have to order all rows of it first, even though I am specifically
pluck over select for performance and memory reasons. Does anyone have
suggestions or ideas for a higher performance method of getting the a
specific column of the last few rows of a table ordered by the primary
I also extremely reccomend mentioning in the pluck API documentation
pluck returns an un-ordered list so others do not fall into the same
mistake I did.