I have a posts table with a JSON column of an array with IDs. This column's data looks exactly like:
[1, 3, 17, 19] These values are not quoted.
To check if a user should see a post, I simply use JSON_CONTAINS(userlist, '(the user ID)', '$'). However, after many thousands of posts, this is starting to get too slow. I'd like to avoid normalizing this to another table with proper relations for now, so I'm wondering what's the best way to see if a user ID exists in a field like what I have.
Note: this is not exactly a duplicate. My values are straight integers, which is why I seemingly can't use JSON_SEARCH()?
SELECT VERSION();return? Are you using MySQL 8.0 so you can create multi-valued indexes? If so, then have you created such an index? If not, then why not?[1, 3, 7]for user IDs 1, 3, and 7.