You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently encountered performance issues with queries that were not utilizing indexes correctly. Upon investigation, I discovered that filtering by date using whereDate()prevented the index on the created_at column from being utilized efficiently.
To address this, I indexed the created_at column and modified my queries to use where() with a datetime value and comparison operators (<= or >=). This approach significantly improved performance.
Hence, I propose adding a new method called indexedTimestamps() to the Blueprint class. This method would automatically index the created_at and updated_at columns when invoked.
By incorporating this feature, Laravel developers would have a convenient way to ensure efficient index usage when filtering by date, leading to improved query performance.
I am willing to contribute to this feature if need be.
I am unclear just why whereDate() doesn't use the index and why where() does. An example for each of the Laravel DB:Query code and the resulting SQL would help us understand the cause a bit better. And then we might want to see if the whereDate() method needs to produce slightly better SQL so that it does use the index.
whereDate() is a Query Builder method. There don't seem to be similar Eloquent methods, so should there be?
I am unclear why adding an indexedTimestamps() method to blueprint will fix the issue of whereDate() not using an index existing on created_at?
I think it would also help to have some before and after examples of creating indexed timestamp fields showing the improvement that you are proposing.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I recently encountered performance issues with queries that were not utilizing indexes correctly. Upon investigation, I discovered that filtering by date using
whereDate()
prevented the index on the created_at column from being utilized efficiently.To address this, I indexed the created_at column and modified my queries to use
where()
with adatetime
value and comparison operators(<= or >=)
. This approach significantly improved performance.Hence, I propose adding a new method called
indexedTimestamps()
to the Blueprint class. This method would automatically index thecreated_at
andupdated_at
columns when invoked.By incorporating this feature, Laravel developers would have a convenient way to ensure efficient index usage when filtering by date, leading to improved query performance.
I am willing to contribute to this feature if need be.
Thank you for considering this suggestion!
Beta Was this translation helpful? Give feedback.
All reactions