firebird icon indicating copy to clipboard operation
firebird copied to clipboard

Building a view in a join unnecessarily

Open ARDInformatique opened this issue 3 years ago • 3 comments

Request on TABLE_A whith a join on VIEW_B.

I don't understand why Firebird builds VIEW_B because the join is lapsed since TABLE_A is empty

SELECT TABLE_A.ID FROM TABLE_A JOIN VIEW_B C USING (ID)

Do you have an explication ?

ARDInformatique avatar Aug 30 '22 15:08 ARDInformatique

Views are not "built", their plan is merged into the outer query plan and then executed as decided by the optimizer. Nobody says TABLE_A should be read first (and be seen as empty), in fact the optimizer may prefer reading from the tables inside the view.

dyemanov avatar Aug 30 '22 17:08 dyemanov

Ok i'm understand by there is no way form force the first read TABLE_A for not reading unnecessarily the VIEW ?

ARDInformatique avatar Aug 31 '22 07:08 ARDInformatique

You can try: SELECT A.ID FROM TABLE_A A INNER JOIN VIEW_B C ON A.ID=C.ID+0

livius2 avatar Sep 01 '22 10:09 livius2