English 中文(简体)
使用 MyISAM 存储引擎的高级 trafic 服务器, 哪个查询在查询优化方面是好的?
原标题:Which Query is good in query optimization as per high trafic server with MyISAM storage engine?

下面是两个查询,每个查询优化观点中,一个是好的。

//Query 1
UPDATE `table_name` SET `column` =  455  WHERE `row_id` =  433200 ;

//Query 2
UPDATE `table_name` SET `column` = `column`+1 WHERE `row_id` =  433200 ;

Thanks, Yogs

最佳回答

我认为,如果不强迫 MySQL 将字符串转换为整数,则差异将微不足道。如果类型是整数,则不要用引号包住数值:

UPDATE `table_name` SET `column` = 455 WHERE `row_id` = 433200;

还有

UPDATE `table_name` SET `column` = `column` + 1 WHERE `row_id` = 433200;

然而,查询会说两种不同的东西。 第一个是您明确设定了值的, 而不是线索。 如果您有两个或两个以上的会话, 两者都试图递增值, 以最后一个运行者为准, 可以设定值, 而其他值则很可能丢失。 例如, 如果三个连接同时运行查询, 则该值可能只加增一次。 为了避免这种情况, 您必须明确锁定 SELECT 之前的表格, 并在更新后释放 。

第二个查询,您在其中加量值,是线条安全。如果三个连接同时运行查询,则该值将加量三次。

问题回答

我建议 row_ id , column 不是一个字符串,而是整数。 如果是这样, 您为什么要求 Mysql 为您转换类型 。

第一个查询速度更快,我想

第二,您有2个额外的操作 - 获取价值和附加值





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签