-
Notifications
You must be signed in to change notification settings - Fork 28
pluck() performance issues (specifically Query\Builder::pluck) #98
Comments
I like the idea, but can you really rely on your fetch mode? After all, it is configurable in config/database.php. That said, maybe we can use either |
Indeed, the code would have to support both array and object fetch modes. My main concern is about the missing values. Could this only happen if the user asked for a nonexistent DB column, or could there be other cases? |
I'm fairly positive this would only happen for invalid (nonexistent) column names, yeah... |
So basically, the only question is: what should happen if the user queries a nonexistent column (which is clearly wrong). Currenty it would return an array of nulls… I suppose it would be okay if the user gets a shitload of "index/property undefined", so he would just fix its code nonetheless. |
That's even simpler: querying a nonexistent column would throw a sql error beforehand… So, I can't think of any technical limitation for optimizing |
The main (and only) concern about implementing the optimization, is proper handling of PDO fetch mode. As it may be of interest when working on this, refs laravel/framework#12171. |
Just as a reminder, one case to keep in mind: if the user has set the connection to Maybe an edge case, but I suppose here we'd want to pluck the class-modified properties, not the original properties from DB. |
I'm open to improvements here if possible. |
PR cross-reference: laravel/framework#23482 |
pluk is there for laravel 5 |
pluck is changed as value() |
I encountered performance issues using
Query\Builder::pluck()
. This is because it usesArr::pluck()
, which callsdata_get()
on each row.data_get()
easily becomes a bottleneck when used in loops.On a tiny 5000 rows test database,
Builder::pluck()
takes 184 ms. Right now, I'm using a custom method which takes 40 ms.I can use this code, because I know:
'fetch' => PDO::FETCH_CLASS
)Maybe this could be of inspiration for implementing a general-purpose optimized method.
The text was updated successfully, but these errors were encountered: