Replies: 1 comment 3 replies
-
We had to change mysql behavior for count when we migrated to mysql 8 due to MVCC to avoid db clogging on millions rows tables and we did it outside the framework via macros. That to would qualify as a RFC if your RFC would get into the framework. Changing this in eloquent just for one of the many supported db types might introduce issues. We would introduce a default sort by pk in a custom eloquent builder if the table has an auto-incrementing/ ordered UUID pk etc.
by overwriting the first method. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The Problem
PostgreSQL's
first()
returns different results than MySQL/MariaDB due to MVCC and query planner behavior:Real Impact:
Root Cause: PostgreSQL MVCC
When you update a row in PostgreSQL:
PostgreSQL creates new row versions on updates, changing physical storage order and affecting
LIMIT
withoutORDER BY
.Proposed Solution
Add conservative auto-ordering to
first()
:Performance: ~0.1-0.5ms overhead, uses existing primary key index.
Alternative Approaches
User::firstOrdered()
'consistent_first' => true
Questions for You
Have you experienced this PostgreSQL inconsistency?
What's your preference?
first()
with conservative auto-orderingfirstOrdered()
method insteadConcerns about changing
first()
behavior?Which databases do you use in production?
Your Experience Matters
This affects every Laravel app using PostgreSQL. Whether you're running multi-database setups, migrating between engines, or just want predictable behavior - your input shapes this decision.
Drop your thoughts below - especially real-world examples of this causing issues or why you think the current behavior should stay!
Beta Was this translation helpful? Give feedback.
All reactions