if you are ordering by it, then creating an index for it is probably a good idea.
Is there any benefit to indexing 'created_at' column?
I'm currently facing an issue where I'm getting SQLSTATE[HY001]: Memory allocation error: 1038 Out of sort memory, consider increasing server sort buffer size error in MySQL 8
The query is pretty simple -
Post::where('type', 'threads')->orderBy('created_at')->cursorPaginate(20);
Note that, the created_at column is not indexd. If I change to ->orderBy('id'), then the error goes away. Upon some researching, I found out that MySQL 8 has this bug that throws memory error if the database has json column. [ Ref: https://bugs.mysql.com/bug.php?id=103225 ]
In production, I'm planning to use either MySQL or Postgres; but wondering if there's any merit to indexing created_at column?
Please or to participate in this conversation.