FirebirdSQL / firebird

Firebird server, client and tools
https://www.firebirdsql.org/
1.26k stars 217 forks source link

Building a view in a join unnecessarily #7285

Open ARDInformatique opened 2 years ago

ARDInformatique commented 2 years ago

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 ?

dyemanov commented 2 years ago

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.

ARDInformatique commented 2 years ago

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

livius2 commented 2 years ago

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