Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

imposition's avatar

Improving Query

$data = TopWireless::select(DB::raw('UserName, sum(AcctInputOctets) as Input , sum(AcctOutputOctets) as Output'))
                    ->whereDate('AcctStartTime' , 'regexp', date($data['date']))->groupBy('UserName')->orderBy('Output', 'desc')->limit(20)->get();

I'm wondering how to improve this query. This is taking too much time to complete.

0 likes
3 replies
bobbybouwmann's avatar
Level 88

You can improve the whereDate already

$date = Carbon::parse('Y-m-d H:i:s', $data['date']);

$query->whereDate('AcctStartTime', $date);

The query doesn't look that slow to me. You can improve a lot by adding the correct indexes.

Please or to participate in this conversation.