Datatable icon indicating copy to clipboard operation
Datatable copied to clipboard

Double "count(*)" query

Open FractalizeR opened this issue 11 years ago • 7 comments

Somehow count(*) query is duplicated in the engine. I can see it in Laravel debug bar.

2014-06-16 23 42 29

Controller code:

public function index()
    {
        if (Datatable::shouldHandle()) {
            return Datatable::query(Customer::query()) // all(array('id', 'firstName', 'lastName', 'phone')))
                ->showColumns('firstName', 'lastName', 'phone')
                ->searchColumns('phone')
                ->orderColumns('lastName', 'firstName')
                ->make();
        }

        return View::make('customers.index');
    }

Template code:

{{ Datatable::table()
    ->addColumn('First name', 'Last name', 'Phone')
    ->setUrl(route('customers.index'))
    ->render() }}

The same issue arises when using the following:

Datatable::query(DB::table('customers')->select(array('id', 'firstName', 'lastName', 'phone')))

FractalizeR avatar Jun 16 '14 19:06 FractalizeR

The first time it will count all entries for the total amount, the second time it will count the entries for the current page:

Showing 1 to 10 of 57 entries

Chumper avatar Jun 16 '14 20:06 Chumper

But the queries are identical. The second one is without LIMIT clause. I have 1000 entries of which only 10 is currently shown.

select count(*) as aggregate from `customers`
select `id`, `firstName`, `lastName`, `phone` from `customers` order by `firstName` asc limit 
select count(*) as aggregate from `customers`

FractalizeR avatar Jun 16 '14 21:06 FractalizeR

i will look into this.

Chumper avatar Jul 06 '14 17:07 Chumper

One query is for the total, unfiltered, amount of items The other query counts the items which matches the filter 1 to 10 from 234 Entries(filtered from 1.000 entries)

niklasdevries avatar Aug 01 '14 23:08 niklasdevries

Well... That's unexpected. And that's not performance-wise. count(*) in InnoDB tables is an expensive operation. It should be controlled by some settings I beleive.

FractalizeR avatar Aug 02 '14 07:08 FractalizeR

I have the same problem, i want to know what happened with this issue!

klapifoch avatar Sep 01 '14 15:09 klapifoch

Imho it works as expected and as the "specification" states, any advise on how to convert it into a setting and how to handle it?

Chumper avatar Sep 15 '14 17:09 Chumper