0

I'm creating a real-estate website and i was wondering if there was a better way of organizing my columns or tables, not sure what would be the best way to go about it, i currently have a lot of columns and im worried about performance issues.

The columns are as follows

  • 5 for things like property id, add date, duration, owner/user id.
  • 35 columns for things like title, description, price, energy rating, location, etc.
  • 40 columns for features like swimming-pool, central heating, river front, garage, well, etc.
  • 15 for image locations which are stored on server
  • 15 for the image descriptions

Is 110+ columns bad practice in MySQL? Everything is lightning fast but i'm in localhost at the mo, wont the monstrous size of the tables slow queries? Especially if I have a couple hundred properties?

Am i ok with my current setup? What would best practice be? How do e-commerce websites that have many feature options go about this?

0

3 Answers 3

2

It is not a good practice since the data can be stored in separate tables. What would help you most would be to create an ERD to visualize how you can organize your tables. Even if you do not understand the ins and outs of ERDs, you can still use it to at least organize your thoughts.

It seems that you already have your tables separated based on the bullet points that you made within your question. One thing that I would add to your bullets is maybe breaking down your features into categories and creating a table for each.

For example, swimming pools and riverfront can be placed in a table called LandscapeFeatures or OutdoorFeatures.

1

Most likely, the property features would be better stored in a separate table, with one row per property feature, rather than as columns in your main table. I understand this as a many-to-many relationship between a propery and its features, so this suggest two more tables:

properties          (property_id (pk), date_added, title, description)
features            (feature_id (pk), description)
property_features   (property_id (fk), feature_id (fk))

Such structure is much more flexible and easier to query than having one column per feature. As examples:

  • easy to add features by creating new rows in the features table (while in the old structure you had to create a new column)

  • easy to aggregate the features, and answer a question like: count how many features each property has

As for images, they should have their ow table too. If an image maby belong to several user, then it's a many-to-many relationship, and you can follow the above pattern. If each image belongs to a single user, one more table is enough:

properties          (property_id (pk), date_added, title, description)
features            (feature_id (pk), description)
property_features   (property_id (fk), feature_id (fk))
images              (image_id, location, description, property_id (fk))
4
  • Thanks for your answer! So i'll split the data up into different tables to make it more efficient right? I suppose each images would belong to only one user as the idea is for them to upload their own properties. But it would still be better practice to keep all images in a separate table anyway, Jun 22, 2020 at 0:12
  • You mention having a features table and having 1 row per feature, how would I then associate each feature to the property (for sale) in question. Do i just add a feature column in the property table and store the features the property has in a string like. "1,5,8,14,17,23,24,35"? Jun 22, 2020 at 0:29
  • 1
    @DominicOrmston: you add more rows to the property_features table: each row represents a property/feature tuple. Try and seach "SQL many-to-many" if the concept is unclear to you.
    – GMB
    Jun 22, 2020 at 0:30
  • A star-schema will be inefficient to query.
    – Rick James
    Jun 23, 2020 at 3:33
1

One table:

  • Columns for the dozen or so values that you are most likely to search on.
  • Devise several composite indexes that involve those columns, starting with the more commonly searched columns.
  • Devise a TEXT column and put "words" in it for a FULLTEXT index. If this is home sales, consider words like "swimming pool septic tank gazebo Eichler". This will help with certain "boolean" type queries. (If you like this idea, let's discuss how to make use of filtering with indexes and/or fulltext; it gets tricky.)
  • Put the rest into a JSON (or TEXT column). Do not plan on searching it; instead bring the row(s) into your app code for further filtering after searching by the actual INDEXes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.