下面是两个查询,每个查询优化观点中,一个是好的。
//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
下面是两个查询,每个查询优化观点中,一个是好的。
//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个额外的操作 - 获取价值和附加值
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 ...
<?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 = ...
我把我的用心从使用QQL转向MySQL。 它与凯科特合作,现在不工作,因为我已经改变,使用MySQL。 这里的错误信息是:
We have a restaurant table that has lat-long data for each row. We need to write a query that performs a search to find all restaurants within the provided radius e.g. 1 mile, 5 miles etc. We have ...
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 ...
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 ...
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 ~...
My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...