0

Let's say I have a query that utilizes two tables, this query works fine and returns the intended results.

SELECT TABLE1.COL, TABLE2.COL
FROM TABLE1, TABLE2
WHERE TABLE1 = 'something' AND TABLE1.ID = TABLE2.ID

Would adding extra tables defined in the schema, along with their foreign key associations slow down my query?

NOTE: The addition of the extra tables does not change what the query returns. The query defined above and the one defined below are equal in "functionality" but are they equal is speed?

SELECT TABLE1.COL, TABLE2.COL
FROM TABLE1, TABLE2, TABLE3, TABLE4
WHERE TABLE1 = 'something' AND TABLE1.ID = TABLE2.ID AND TABLE3.ID = TABLE4.ID
Felipe Rios
  • 101
  • 2
  • 10
  • Learn to write proper queries using `JOIN` before worrying about performance or foreign key references. – Gordon Linoff Apr 18 '17 at 21:36
  • 1
    I think you have (essentially) an OUTER JOIN there since you don't make and JOIN between tables 1&2 and tables 3&4. Using the 'JOIN ... ON' syntax for JOINing would make this query more clear. – Dan Apr 18 '17 at 21:36
  • Adding indexes on, say, `table1` shouldn't have a direct adverse effect on `table2`. Additionally, the `SELECT` queries wouldn't really be affected negatively by the new indexes, although they might likely slow down the `INSERT`, `UPDATE` and `DELETE` operations. Indexes could be very useful, but adding them where they aren't required won't do any good. Please see this post to know more about [when and how to use indexes](http://stackoverflow.com/q/3049283/2298301) – Dhruv Saxena Apr 18 '17 at 21:55

0 Answers0