HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Do non-relevant columns affect query time of select statements?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
columnsnonstatementsquerytimeaffectrelevantselect

Problem

I'm just curious.

Say you have a table of 1 million records/ rows.

select order_value from store.orders


Does it make a difference whether that table has 1 field, 2 fields, or 100 fields, in actual query time? I mean all fields other than "order_value."

Right now I'm pushing data to a data warehouse. Sometimes I dump fields into the table that "may be used in the future, someday" - but they aren't being queried right now, by anything. Would these 'extraneous' fields affect select statements that do no include them, directly or indirectly (no * I mean)?

Solution

It depends, on the table structure and the available indexes.

-
Case A: Common (rowstore) table, no index on (order_value).

The only possible execution plan is to read the whole table (which is of course much different when it's 2 vs 200 columns, so a few vs a few thousand bytes wide).

-
Case B: Common table, there is an index on (order_value) or some other indexes that include that column.

There is a better plan now, scan the whole index (one of them) - which is of course much more narrow than the whole table, just a few bytes. Which makes irrelevant if the table has 2 or 200 columns. Only the index is scanned.

-
Case C: It's a columnstore table.

As the name implies, the structure of these tables are column-wise oriented, not row-wise. There is no need for any index, the table design itself is suited for reading entire columns.

Context

StackExchange Database Administrators Q#187807, answer score: 12

Revisions (0)

No revisions yet.