I have a report using DataTables with server side processing on, that searches through 3 million plus records. The query pulls data from 2 different tables and I use Left Join and Union All in the query. There are 7 inputs and my report has 7 columns that it displays. I have Paginate and Search options on.
A typical search takes around 1 minute 15 seconds to complete. When I click on different page or try to use the search function, it takes around 1 minute for it to change or to show the search results, respectively.
Is there anyway to speed this up?
Here's a snippet from my view.php. I omitted the other inputs and columns, but they're basically the same.
<?php
use \koolreport\datagrid\DataTables;
use \koolreport\inputs\Select2;
?> <html>
<div style="margin:30px;">
<head>
<title>Search All Tables</title>
</head>
<body>
<h1>Search All Tables</h1>
<form method="get">
<div class="row">
<div class="col-sm-1">
From Quarter:
<?php
Select2::create(array(
"name"=>"startQtrPicker",
"dataSource"=>$this->src("mysql2")->query("
SELECT YearQtr
FROM YearQtr
ORDER BY YearQtr DESC
"),
"attributes"=>array(
"class"=>"form-control"),
));
?>
</div>
<div class="col-sm-1">
To Quarter:
<?php
Select2::create(array(
"name"=>"endQtrPicker",
"dataSource"=>$this->src("mysql2")->query("
SELECT YearQtr
FROM YearQtr
ORDER BY YearQtr DESC
"),
"attributes"=>array(
"class"=>"form-control"),
));
?>
</div>
</div>
<div class="form-group" style="margin-top:22px;">
<button class="btn btn-md btn-primary">Search</button>
</div>
</form>
</div>
</div>
<?php
DataTables::create(array(
'name' => 'AllTabless',
"cssClass"=>array(
"table"=>"table table-striped table-bordered"),
'dataSource' => function() {
return $this->src('mysql2')
->query('
#TABLE1
SELECT
YearQuarter AS "YrQtr",
Group1.Title AS "Name",
Dollars AS "Revenue"
FROM (TABLE1
LEFT JOIN Group1 ON Group1.__kp_Name_ID=TABLE1._kf_Name_ID
)
WHERE 1=1
'.(($this->params["startQtrPicker"]!=array())?"and YearQuarter BETWEEN :startQtrPicker AND :endQtrPicker":"").'
UNION ALL
#TABLE2
SELECT
YearQuarter AS "YrQtr",
Group1.Title AS "Name",
Amount AS "Revenue"
FROM (TABLE2
LEFT JOIN Group1 ON Group1.__kp_Name_ID=TABLE2._kf_Name_ID
)
WHERE 1=1
'.(($this->params["startQtrPicker2"]!=array())?"and YearQuarter BETWEEN :startQtrPicker2 AND :endQtrPicker2":"").'
')
->params(array(
":startQtrPicker"=>$this->params["startQtrPicker"],
":endQtrPicker"=>$this->params["endQtrPicker"],
":startQtrPicker2"=>$this->params["startQtrPicker2"],
":endQtrPicker2"=>$this->params["endQtrPicker2"],
));
},
"options" => array(
"searching" => true,
"paging" => true,
"colReorder" => true,
"pageLength" => 25,
),
"serverSide"=> true,
));
?>
</body>
</html>