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 

and this one.

SELECT p.first_name, p.last_name, ....
FROM tbl_person p 
WHERE p.tbl_person_id=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?

  • The only thing that changes is the first increases network traffic in case "if the query has a few hundred times more character". The query has 1 table only and does not require any alias at all – sepupic Jul 26 '17 at 8:58
  • why some comments here is gone? including my comment. – zer09 Jul 29 '17 at 1:50

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.

  • Thanks for the answer, BTW does the tokenized statement handled by the server or by a programing language? How about using transactions? – zer09 Jul 26 '17 at 12:55
  • @zer09 Tokenization is performed by the DBMS. Transactions will have no influence. – Michael Green Jul 27 '17 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.