You could create a computed column that persistently stores the information:
alter table table_name
add column text_has_slash tinyint
generated always as (text_col like '%/%')
stored
;
Or, if you want to treat null
values as negatives:
generated always as (coalesce(text_col like '%/%', 0))
The column value is computed and stored in the table (it is automatically updated by the database when the value changes).
Now you can use that column in your query:
select * from table_name where not text_has_slash;
Demo on DB Fiddle
Filtering on a pre-computed value should already improve performance.
Creating an index on a boolean column does not necessarily help, because there are only three possible values (0, 1, null). Unless the values are very unevenly distributed, it is often faster for the database to perform a full scan. On the other hand, you might want to include this column in a multi-column index, if you have more search criteria than those you have shown.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…