Check if the table already has a WHERE condition in the Laravel query generator
1. Reference: In mysql 8.0, when the total number of table records is checked, the analysis and optimization of the timeout is optimized. Add WHERE ID > 0 when a COUNT SQL does not exist where condition exists.
2. Reference:How to check if table is already has a where Clause in Laravel Query Builder? The final implementation is as follows
if (empty($builder->getQuery()->wheres)) {
$builder->where('id', '>', 0);
}
3. The final generated sql is as follows, which is in line with expectations
select count(*) as aggregate from `tables` where `id` > 0