MySQL选择/插入/更新,排序有问题吗? [英] MySQL select/insert/update, does column order matter?

查看:160
本文介绍了MySQL选择/插入/更新,排序有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的mysql数据库中,我有字段id,名称,电子邮件,年龄,城市,电话。按顺序



这些顺序是否以速度/其他方式选择/插入/更新?

如果我说

 选择手机,城市,姓名,年龄,电子邮件FROM tablename 
//混合顺序

  SELECT id,name,email,age,city,phone FROM tablename 
//列的原始顺序

编辑:不仅仅是一个小的简单查询(只是一个例子)。关注也是100.000行和多个/高级查询和循环

解决方案

不,不管你选择什么顺序。要提高速度,您可以使用索引或只选择实际需要的列。选择时,它们将按您选择的顺序返回。您还可以使用GROUP BY按特定列对结果进行分组。



这不会产生任何影响。



但是,省略SELECT子句中的列将使其运行更快,因为它将通过网络发送更少的数据。



源:在select语句中的列的顺序影响查询速度?


In my mysql db I have the fields id, name, email, age, city, phone. In that order

Does the order in which I select/insert/update these matter, in terms of speed/other?

If I say

SELECT phone, city, name, id, age, email FROM tablename
// mixed up order

As opposed to

SELECT id, name, email, age, city, phone FROM tablename
// original order of columns

EDIT: not only for one small simple query (just an example). Concern is also for 100.000 rows and multiple/advanced queries and loops

解决方案

No, it doesn't matter what order you select from. To increase speed to you can use indexes or only select the columns you actually need. When selecting, they would be returned in the order you select. You can also use GROUP BY to group the result by a particular column.

"That won't make any difference.

However, omitting columns from the SELECT clause will make it run faster since it'll send less data over the network."

Source: Does the order of columns in a select statement affect query speed?

这篇关于MySQL选择/插入/更新,排序有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆