I started using 'ANY()' function in query instead of 'IN' due to some parameter bound error. Currently it's something like that.
Select *
FROM geo_closure_leaf
WHERE geoId = ANY(:geoIds)
But it has a huge impact on performance. Using the query with IN is very much faster than with ANY.
Any suggestion how can we bound array of string parameters can be passed in 'IN' expression.
I have tried temporary fix using
Select *
FROM geo_closure_leaf
WHERE geoId IN (''('' || array_to_string(:geoIds::text[] ,''),('') || '')'')
Select *
FROM geo_closure_leaf
WHERE geoId IN (select unnest(:geoIds::text[]))
geoIds = array of strings
It's working this way.
**public override T Query<T>(string query, IDictionary<string, object> parameters, Func<IDataReader, T> mapper)**
{
T Do(NpgsqlCommand command)
{
IDataReader reader = null;
try
{
** command.CommandText = query;
reader = command.AddParameters(parameters).ExecuteReader();**
return mapper(reader);
}
finally
{
CloseDataReader(reader);
}
}
return Execute(Do);
}
Object is array of string.
Expected is: I should be able to do this without having to put extra logic in sql.
Select *
FROM geo_closure_leaf
WHERE geoId IN (:geoIds)
INinto= ANY, so that is surprising. Can we haveEXPLAIN (ANALYZE, BUFFERS)output for both queries?"Seq Scan on geo_closure_leaf (cost=0.00..12.13 rows=2 width=436) (actual time=0.000..0.000 rows=0 loops=1)" " Filter: (("geoId")::text = ANY ('{a,b}'::text[]))" "Planning time: 0.075 ms" "Execution time: 0.022 ms"With Any operator any idea how can i run the query in pgadmin?Select * FROM geo_closure_leaf WHERE geoId IN (select unnest(:geoIds::text[]))INis transformed into= ANYand is able to use indexes. Earlier versions do not use indexes when using arrays. The problem is likely the use of an old server.