I have a table for real estate properties in which features for a real estate property are stored in serialised array. Example, a house can have wifi, pool, garden and so on other miscellaneous features. These features form a list, array with values, and are serialised and stored in table column named features. When I have to display these features I fetch the serialise array, unserialise it and display it. Now, using this table, how can I search for a house which has Wifi AND Pool? Secondly, this structure was good till the time search was out of scope but I am willing to modify it if there are strong reasons, apart from search, to change it.
Update
The feature wifi can be spelled as “Wifi” or “WiFi available” or “equipped with wifi” or anything. So wifi is a keyword and features are actually input by property owners so similar features can differ. Hence the idea was to save features in a serilised array
PHPs serialize format (or JSON) are no native data types in SQL. But XML for example would be. But that’s often likewise overkill.
An alternative to the separate tables approach would be a CSV list of present features (native to SQL thanks to
FIND_IN_SET).Otherwise you can use some guesswork to prefilter the search query with
WHERE options REGEXP 's:4:"Pool";b:1'when you want to keep the serialized data blob. (You would need to know the exact serialization scheme for each property you are looking after.)For data sets that do not concern the database I consider that appropriate even. But since you are using the DB mostly for searching jus that data blob, you should reconsider.