How to set random datetime in MySQL

Imagine you have to mass insert or update the values in your created_at or updated_at fields. You can easily achieve that with the following SQL query: You can also choose the spread in seconds, 3600 is 1 hour, 86400 is 1 day, 31536000 is 1 year.

How to make queries to large tables in Laravel

You should avoid using SQL functions in your Laravel Eloquent queries because they inflict full table scans. This happens due to database mechanisms – the condition is not applied until the date function has been run. It will produce a query like this: The better way: So we get this exact query, without the date() […]

How to create indexes in the right way

The science of creating database indexes is learned from experience and the right people, not to mention much more complicated multiple-column indexes. But it wasn’t supposed to be complex! Here are three simple pieces of advice for the column ordering of multiple column indexes, solving 90% of the performance issues. Three rules for Multiple-Column Indexes […]