Which is faster “where col = ? or col = ? or col = ?” OR “where col in (?, ?, ?)” in C with informix (.ec/esql)?

StackOverflow https://stackoverflow.com/questions/7384294

  •  29-10-2019
  •  | 
  •  

Question

Our code is written in C and DB is Informix. We are doing some code optimization in ESQL program and found the following query:

UPDATE [TABLE] SET [PRIMARY KEY COLUMN] = [NEW KEY] WHERE COL = ? OR COL = ? ...

The number of columns in the where clause is dynamically prepared. We have an upper count check to stop preparing the where clause and do an update, then come back and start preparing the remaining. The UPPER_MARK is "30"

if ( where_parameter_count >= UPPER_MARK )
__ execute update__
__ clean_and_continue; /* start prepare again */__

We thought of replacing the WHERE .. OR with WHERE ... IN

UPDATE [TABLE] SET [PRIMARY KEY COLUMN] = [NEW KEY] WHERE COL IN (?, ? ...)

Will this be faster than "where or"?

Was it helpful?

Solution

Either syntax resolves down to the same thing as far as the Query Optimizer is concerned. It won't make any difference.

The only advantage to the in-list approach is that adding additional predicates won't change the logic, i.e.

x IN (a, b) AND y = z

and

x = a OR x = b AND y = z

are NOT the same thing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top