I have a postgres database table with 2 million records and a script that selects rows based on a certain column being NULL. It then modifies the data, storing values in the NULL column and then selects the next batch of data to process. However, the following query that retrieves the rows with NULL values is extremely slow:
SELECT id, name, data_values FROM my_table WHERE data_values is NULL;
data_values is of type JSONB. data_values is not currently indexed, but my research suggests that postgres indexes do not store NULL values so this would not help.
Are there workarounds for speeding up the SELECT query? Store a boolean in indexed column? Filtered indices?
create index on my_table (id, name) where data_values is null