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; and determining whether to create on-demand, by the at least one processor, a hash index based on the comparing.