Does the order of columns in a query matter?

后端 未结 3 891
花落未央
花落未央 2021-02-20 04:09

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

相关标签:
3条回答
  • 2021-02-20 04:32

    In practice, I suspect it might.

    With a decent query optimiser: it shouldn't.

    You can only tell for your cases by measuring. And the measurements will likely change as the distribution of data changes in the database.

    with regards

    Wazzy

    0 讨论(0)
  • 2021-02-20 04:35

    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.

    0 讨论(0)
  • 2021-02-20 04:36

    The order of the attributes selected is negligible. The underlying storage engines surely order their attribute locations, but you would not necessarily have a way to know the specific ordering (renames, alter tables, row vs. column stores) in most cases may be independent from the table description which is just meta data anyway. The order of presentation into the result set would be insignificant in terms of any measurable overhead.

    0 讨论(0)
提交回复
热议问题