mysql - Is it faster to only query specific columns? -
i've heard faster select colums manually ("col1, col2, col3, etc") instead of querying them "*".
but if don't want query columns of table? faster query, example, "col1, col2" insteaf of "col1, col2, col3, col4"?
from understanding sql has search through of columns anyway, , return-result changes. i'd know if can achieve gain in performance choosing right columns.
(i'm doing anyway, backend api of 1 of applications returns more not columns, i'm thinking letting user manually select columns want)
in general, reducing number of columns in select minor optimization. means less data being returned database server application calling server. less data faster.
under circumstances, minor improvement. there cases improvement can more important:
- if covering index available query, index satisfies query without having access data pages.
- if fields long, records occupy multiple pages.
- if volume of data being retrieved small fraction (think < 10%) of overall data in each record.
listing columns individually idea, because protects code changes in underlying schema. instance, if name of column changed, query lists columns explicitly break easy-to-understand error. better query runs , produces erroneous results.
Comments
Post a Comment