rails - pluck vs map

访问量: 382

refer to:  https://stackoverflow.com/questions/45347317/which-one-is-faster-between-map-collect-select-and-pluck

pluck:  pick 1 attribute from array

map: re-implement your function

my_array.map(&:id)

my_array.pluck(:id) 

the same.  pluck faster than map

XXTransaction Pluck (0.3ms)  SELECT "xx_transactions"."id" FROM "xx_transactions" WHERE "xx_transactions"."id" = $1  [["id", 18068574]]
XXTransaction Load (0.5ms)  SELECT "xx_transactions".* FROM "xx_transactions" WHERE "xx_transactions"."id" = $1  [["id", 18068574]]

订阅/RSS Feed

Subscribe