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

Does query string length matter?

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

Problem

It could be just a question for a micro-performance, but it always keeps coming back to my head (just making me crazy). I can't find any answer in Google about it. I just want to clarify it.

I have these two example queries.

SELECT tbl_person.first_name, tbl_person.last_name, ....
FROM tbl_person 
WHERE tbl_person.tbl_person_id=1 
LIMIT 1


and this one.

SELECT p.first_name, p.last_name, ....
FROM tbl_person p 
WHERE p.tbl_person_id=1 
LIMIT 1


Is there any advantage or disadvantage between them?

I know the second one is easier to read and write, but it doesn't matter because the query will be just generated.

I am interested in performance impact. If the query has a few hundred times more characters, does it hurt performance?

Solution

does it would hurt performance

Not in any significant way. The initial parsing may take a little longer, as might the network transfer (though for hundreds or even thousands of characters you are not going to really see that unless you are talking to the server over a cellular connection or such!), but after that stage the query planner will be given the same tokenised statements whether you used table aliases or not. Time spent in the query planner's realm will be much more significant than the parsing+tokenising time, and running the resulting plan will usually be orders of magnitude more expensive again.

tl;dr: if there is a performance difference it will be practically undetectable.

Context

StackExchange Database Administrators Q#181818, answer score: 4

Revisions (0)

No revisions yet.