我的数据库中有100多万条记录.如何更快地繁殖.


I have 1 million+ records in my database. How to paginate it faster..?

我在数据库中有100多万条记录。

在索引页上,多个筛选器通过数据库createwhere子句进行筛选。例如

从primaryinfo中选择*,其中category='abc'和technology='PQR'

我想展示--:1.找到的记录数2.页码。3.这一页100分中有10分。

我将过滤后的记录作为json对象发送到jquery,在记录中循环并附加到特定的div

下面是我的php分页代码

$selectQ = "select * from primaryinfo where  match(title,description,tags)       against('".$searchCombine."') and category='abc' and technology='pqr'";
$result = mysql_query($selectQ);
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);
$start;
$end;
if (isset($_POST['pagecc']))
{
$show_page = $_POST['pagecc'];  
if ($show_page > 0 && $show_page <= $total_pages)
{
    $start = ($show_page - 1) * $per_page;
    $end = $start + $per_page;
} else
{ 
        $start = 0;              
    $end = $per_page;
}
 }
else
{ 
$start = 0;
$end = $per_page;
} 
if($end > $total_results)
    $end = $total_results; 
for($i=$start;$i<$end;$i++){
// here the json object is created
}

首先您可以获得总数:

select COUNT(*) from primaryinfo 
where  match(title,description,tags) against('searchCombine') 
       and category='abc' 
       and technology='pqr' 

然后您可以使用LIMIT功能进行分页:

select * from primaryinfo 
where  match(title,description,tags) against('searchCombine') 
       and category='abc' 
       and technology='pqr' 
LIMIT 0 10; -- Start at offset 0 show ten items per page

请注意,mysql_*函数已弃用,并将在未来的PHP版本中删除。请考虑使用mysqliPDO

为了进一步提高性能,可以考虑在列上设置索引。特别是类别和技术栏,但这将取决于您的数据。