本文介绍了更多时间消耗/CPU 扩展 INSERT IGNORE 或 Select Count(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个程序,我必须检查数百个变量以查看它们是否已经在数据库中.通常需要一段时间才能运行.我正在对所有变量使用 INSERT IGNORE.我应该更改它以首先检查它们是否存在于数据库中吗?哪个功能为最终用户增加了更多等待?

I'm working with a program where I have to check hundreds of variables to see if they are already in the database. It usually takes a while to run. I'm using INSERT IGNORE for all the variables. Should I change this to check if they exist in the database first? Which function adds more wait to to the end user?

在这个程序中,大部分插入都是重复的.所以这种情况会经常出现.

In this program, most of the inserts will be duplicates. So this situation will come up pretty often.

也许在尝试插入之前删除重复项最有意义?(我正在使用 PHP IMAP 库和电子邮件)

Maybe it would make the most sense to get rid of duplicates before attempting to insert? (I'm working with PHP IMAP library & emails)

推荐答案

首先绝对不要先 SELECT 然后再 INSERT,那完全没有意义.相反,请考虑以下内容;

First of all definitely don't do a SELECT and then INSERT, that's completely pointless. Instead, think about the below;

  • 这些是什么类型的设置?它们真的应该属于数据库还是 PHP 配置文件?
  • 调查LOAD DATA INTO,它默认在重复键上使用IGNORE.
  • 一直检查真的很必要吗?当然这只会在安装/设置时完成?
  • What kind of settings are these? Should they really belong in the database or in a PHP config file?
  • Investigate into LOAD DATA INTO which uses IGNORE on duplicate key by default.
  • Is it really nessasary to check all the time? Surely this will be only done upon installation/setup?

这篇关于更多时间消耗/CPU 扩展 INSERT IGNORE 或 Select Count(*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 06:07