6. The method of claim 1 , wherein the first database query comprises one of a correlated sub-query and a nested loop push down join query.
1. A method for creating a hash index on-demand and reusing the hash index for queries in a database, comprising: determining, by at least one processor, during query optimization that a first database query has a query execution plan comprising a sub-query which executes N times a correlated predicate having an operator being one of equal and not equal to a base column; comparing, by the at least one processor, based on the correlated predicate, a cost of creating a hash index and probing the hash index N times to a cost of fully scanning the base column N times; creating on-demand, by the at least one processor, a hash index based on the comparing; and executing, by the at least one processor, a second database query using the hash index, wherein the executing eliminates fully scanning the base column N times.