I have a table with over 500 columns, dynamically created and named by the user. New columns can be created by the user, but none can be deleted.
I was given the task to program a keyword search that searches through all columns for a specific string, and returns the ID of that record. As you can imagine, the query currently looks something like:
SELECT form_id FROM table_name WHERE col1 LIKE '%str%' OR col2 LIKE '%str%' or col3 LIKE '%str%'.. etc.
It is unbelievably slow. To combat this, I'm trying to create another table, where this data is stored in a different format like this:
form_id, col_name, value
1, 'col2', 'some random value'
1, 'col1', 'another random value'
And then searching using:
SELECT id FROM new_table_name WHERE value LIKE '%str%'
I can export all the data and format it, and insert it into the new table. But how would I go about keeping the new table updated? Is it possible to have triggers that automatically insert/update the new table when the original one is modified? Even though I don't know the column names before hand?