duanguanzai6181 2016-10-04 04:05
浏览 50

如何减少mysql查询的内存和CPU使用?

I have more 300,000 rows in my table.I want to remove duplicate row and same data. So I run these query.

$sql=mysql_query("SELECT DISTINCT n1.id FROM dv2xp_adsmanager_ads n1, dv2xp_adsmanager_ads n2 WHERE n1.id < n2.id AND n1.ad_imgone = n2.ad_imgone AND n1.ad_text = n2.ad_text  LIMIT $start,$limit ");

These query can show duplicated row.But this is very slow and increased cup usage to 100% on my server. How to resolve these solution?

  • 写回答

1条回答 默认 最新

  • dongshang1529 2016-10-04 04:12
    关注

    Without knowing much about the data you're using, my best guess is that you could work with INNER and OUTER JOIN. DISTINCT will bring distinctive results based on the main key, but if you have multiple tables with multiple keys, the results might not be optimal. For that reason, it is better to use the JOINs in order to bring just the essential data from each table.

    This is a nice article about JOINs:What is the difference between “INNER JOIN” and “OUTER JOIN”?

    I hope this information helps and puts you in the right direction.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据