Will the SQL statement stop execution at the first match in the OR statement?

I am trying to understand how the next statement will be executed in several entries.

SELECT * FROM test WHERE product='$product' AND (summary LIKE '%$keywords%' OR exp LIKE '%$keywords%') ORDER BY `$order_by` DESC; 

I am new to SQL, so here is what I would like to know:

1. When you execute an SQL query, I believe that it looks at every row in the table. When a match is found, where does it temporarily save the result until all results are returned?

2. In the above example, we say that we are looking at one row in the table, and there is a correspondence for summary . Will the request continue executing OR exp LIKE '%$keywords%' when a match is already found?

+6
source share
2 answers
  • It depends on the database engine to decide how to save the temporary result. Each implementation of the database engine may be different. What the client receives is a set of results consisting of rows (if the query gives a result at all)

  • No, if the first condition in OR is true, it will not check the second condition (which, in any case, you already know the final result)

+2
source
  • In memory, depending on the DBMS.
  • when he finds a match, he probably will not continue. It all depends on the specific implementation of SQL, but in general it would be inappropriate to continue searching for matches, so I would say probably not.
+1
source

All Articles