Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php on line 15

Warning: Cannot modify header information - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/global.func.php on line 170

Notice: Undefined index: include in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php on line 351

Warning: Cannot modify header information - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/global.func.php on line 170

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 145

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 245

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 245

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 245

Notice: Undefined index: visitedfid in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/forum.func.php on line 110

Notice: Undefined index: visitedfid in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/forum.func.php on line 122

Warning: Cannot modify header information - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/global.func.php on line 170

Notice: Undefined index: allowreply in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/viewthread.php on line 345

Notice: Undefined index: allowpost in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/viewthread.php on line 346
AbyssalSwamp 定制与源代码Technology Exchange - Case Board(C版) - GET到新知识了。使用 SELECT 1 来提高查询性能,因为它比选择实际的列更轻量级。 - www.caffz.com
AbyssalSwamp  ActivaUser
» Guest:  Register | Login | 冻结用户(激活) | Residents
Notice: Undefined index: links in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/forumdata/templates/1_header.tpl.php on line 59

RSS subscription to this AbyssalSwamp  

Previous thread Next thread
       
Title: GET到新知识了。使用 SELECT 1 来提高查询性能,因为它比选择实际的列更轻量级。  
  This topic was added by com at 2024-11-22 11:53 移动 
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3867
码币MB 2624 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
GET到新知识了。使用 SELECT 1 来提高查询性能,因为它比选择实际的列更轻量级。



UPDATE A
SET USER = (
    SELECT username
    FROM MEM
    WHERE MEM.UID = A.UID
)
WHERE EXISTS (
    SELECT 1
    FROM MEM
    WHERE MEM.UID = A.UID
);
在上述 SQL 语句中,SELECT 1 是一个简单的子查询,该子查询的目的是检查是否存在匹配条件的记录。SELECT 1 可以理解为选择任意一列并返回一个常量值 1。

在这个特定的情况下,SELECT 1 子查询被用作 EXISTS 子句的参数。EXISTS 子句用于测试子查询是否返回任何结果,如果有至少一条记录存在,则 EXISTS 返回 true,否则返回 false。

因为在 EXISTS 子查询中我们只关心是否存在匹配的记录,而不需要实际的结果或具体的列,所以可以使用 SELECT 1 来提高查询性能,因为它比选择实际的列更轻量级。

总结:SELECT 1 是一个常用的惯例,在 EXISTS 子句中用来检查是否存在匹配的记录,它的具体值并不重要,只是用作占位符来指示存在与否。

Notice: Undefined variable: relatedkeywords in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/forumdata/templates/1_viewthread.tpl.php on line 208




CAFFZ.com
2023-7-11 11:02#1
View profile  Blog  Send a short message  Top
       


  Printable version | Recommend to a friend | Subscribe to topic | Favorite topic  


 


All times are GMT+8, and the current time is 2025-8-31 17:09 Clear informations ->sessions/cookies - Contact Us - CAFFZ - ZAKE
 


Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/urlcheck.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/urlcheck.php on line 2