查询中的列顺序重要吗? [英] Does the order of columns in a query matter?

查看:86
本文介绍了查询中的列顺序重要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从MySQL表中选择列时,与列在表中的顺序相比,选择列的顺序是否会影响性能(不考虑可能覆盖列的索引)?

When selecting columns from a MySQL table, is performance affected by the order that you select the columns as compared to their order in the table (not considering indexes that may cover the columns)?

例如,您有一个包含uid,name,bday行的表,并且具有以下查询.

For example, you have a table with rows uid, name, bday, and you have the following query.

SELECT uid, name, bday FROM table

MySQL是否会以不同的方式看到以下查询,从而导致性能下降?

Does MySQL see the following query any differently and thus cause any sort of performance hit?

SELECT uid, bday, name FROM table

推荐答案

实际上,顺序并不重要,因此您可以根据需要随意订购.

The order doesn't matter, actually, so you are free to order them however you'd like.

我想更多的背景知识将有所帮助:据我所知,优化任何查询的过程都在确定确切地提取行数据的哪个子集之前进行.因此,查询优化器首先将其分解为要查看的表,要执行的联接,要使用的索引,要应用的聚集等,然后检索该数据集.列排序发生在数据提取和结果集的形成之间,因此数据实际上按照数据库的顺序到达",然后在返回到您的应用程序时进行重新排序.

edit: I guess a bit more background is helpful: As far as I know, the process of optimizing any query happens prior to determining exactly what subset of the row data is being pulled. So the query optimizer breaks it down into first what table to look at, joins to perform, indexes to use, aggregates to apply, etc., and then retrieves that dataset. The column ordering happens between the data pull and the formation of the result set, so the data actually "arrives" as ordered by the database, and is then reordered as it is returned to your application.

这篇关于查询中的列顺序重要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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