I have a database on Google Cloud SQL. It contains a simple table that looks like this:
url_id user_id
url_id is a string containing an integer number, user_id is a 14 char string. I have an index on url_id:
CREATE INDEX index_test ON table1 (url_id);
The request I want to run is to get the number of distinct user_id that has an url_id that is not in a list of given ids. I do it this way:
SET work_mem='4GB';
select count(*) from (select distinct afficheW from table1 where url_id != '1880' and url_id != '2022' and url_id != '1963' and url_id != '11' and url_id != '32893' and url_id != '19' ) t ;
Result:
count
---------
1242298
(1 row)
Time: 2118,917 ms
The table contains 1.8M lines. Is there a way I can make this type of request faster ?