4

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?

2
  • 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 Commented Jul 26, 2017 at 8:58
  • why some comments here is gone? including my comment. Commented Jul 29, 2017 at 1:50

1 Answer 1

4

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.

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.