Mysql is inefficient. I'd like to ask you to take a look at it. What's wrong with it?

one of my websites is php+mysql,. Now there is a problem.

there are two data tables: an and B. Table A has 240000 items of data, and Table B now has 24000 items of data.

extract 50 pieces of data from datasheet A, and then generate a html page. It takes about 3 seconds for
to extract 50 pieces of data from datasheet B, and then generate a html page. It takes about 20 seconds.

tables with less data take more time. The extraction code is as follows

<?php
$sql=$empire->query("select * from {$dbtbpre}ecms_rhesis where pote="$navinfor[title]" order by onclick desc limit 50");   
while($nr=$empire->fetch($sql))        //
{
$mytitleurl=sys_ReturnBqTitleLink($nr);  
$nr2=$empire->fetch1("select * from {$dbtbpre}ecms_poetry where title="$nr[heading]" union select * from {$dbtbpre}ecms_classical_chinese where title="$nr[heading]"");
$mytitleurl2=sys_ReturnBqTitleLink($nr2);
?>
<li><a href="<?=$mytitleurl?>"><?=$nr[title]?></a> - - - <a href="[!--titleurl--]"><?=$navinfor[title]?></a> - - -<a href="<?=$mytitleurl2?>"><?=$nr[heading]?></a></li>
<?php
}
?>

the above code extracts 50 items from 24000 data in 20 seconds

< hr >
<?php
$sql=$empire->query("select * from {$dbtbpre}ecms_poetry where pote="$navinfor[title]" union select * from {$dbtbpre}ecms_classical_chinese where pote="$navinfor[title]" order by onclick desc limit 50"); 
$nr3=$empire->fetch1("select * from {$dbtbpre}ecms_poet where title="$navinfor[title]"");
$mytitleurl3=sys_ReturnBqTitleLink($nr3);
while($pr=$empire->fetch($sql))        //
{
$mytitleurl=sys_ReturnBqTitleLink($pr);
$t=$empire->fetch1("select tagid from {$dbtbpre}enewstagsdata where id="$pr[id]"");
$tn=$empire->fetch1("select tagname from {$dbtbpre}enewstags where tagid="$t[tagid]"");
?>
<li><a href="<?=$mytitleurl?>"><?=$pr[title]?></a> - - <a href="<?=$mytitleurl3?>"><?=$pr[pote]?></a> - - <a href="<?=$public_r["newsurl"]?>tags-etagid<?=$t[tagid]?>-0.html"><?=$tn[tagname]?></a> - - <?=esub(strip_tags($pr[newstext]),160,"...")?></li>
<?php
}
?>

the above code takes 3 seconds to extract 50 items from 240000 data.

now the question is: why do those with a large amount of data take less time?

Mar.12,2021

title is not indexed

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bea885-319fe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bea885-319fe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?