10. A system for creating a hash index on-demand and reusing the hash index for queries in a database, comprising: a memory; and at least one processor coupled to the memory and configured to: determine 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; determine, based on the correlated predicate, a comparison of 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; create on-demand a hash index based on the comparison; and execute a second database query using the hash index, wherein the execution eliminates fully scanning the base column N times.
10. A system for creating a hash index on-demand and reusing the hash index for queries in a database, comprising: a memory; and at least one processor coupled to the memory and configured to: determine 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; determine, based on the correlated predicate, a comparison of 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; create on-demand a hash index based on the comparison; and execute a second database query using the hash index, wherein the execution eliminates fully scanning the base column N times. 11. The system of claim 10 , the at least one processor further configured to determine that the cost of creating the hash index and probing the hash index N times is less than fully scanning the base column N times, create the hash index, and use the hash index during query execution to apply the correlated predicate.