The difference in performance sounds more like an issue with your environment than the query.
What are you running your development environment on?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a DB view called 'barcode_filter'
Calling a select query using Query Builder
$menu = DB::table('barcode_filter')->select('short_descip','short_descip1', 'retail1', 'barcode','dept_code','tax_perc', 'tax_flag','availability','qty_check','recipe_item_code','recipe_qty','preparation_time','discount_amt','discount_flag')
->where('company_code',2)
->where('branch_code',$branchCode)
->where('dept_code',$departmentCode)
->where('online',1)
->where('avail',1)
->get();
It took 4.17s to return the result
Then I tried SQL
$menu = DB::select('SELECT short_descip,short_descip1,retail1,barcode,dept_code,tax_perc,tax_flag, qty_check,recipe_item_code,recipe_qty,preparation_time,discount_amt,discount_flag
FROM kloudc5_demo.barcode_filter where company_code = 2 and branch_code = '.$branchCode.' and dept_code = '.$departmentCode.' and online = 1 and avail = 1');
it only took 637ms to return the result
Why this much difference. Used ajax for both queries.
Please or to participate in this conversation.