I am wracking my brain trying to figure out the best way to design the database. The database will store real estate data. My biggest concern is speed of searching.
Lets say I have a home which has 150 different attributes to it. Example attributes would be price, year built, square footage, number of stories, number of bedrooms, high school which home is zoned for, roofing description, or landscape description. I am making a separate table for all 150 attributes and one table to contain property numbers.
CREATE TABLE `property` (
`id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT ,
`timeadded` TIMESTAMP NOT NULL ,
`timeupdated` TIMESTAMP NOT NULL ,
PRIMARY KEY ( `id` )
);
CREATE TABLE `bedrooms` (
`fkey_prop` MEDIUMINT UNSIGNED NOT NULL ,
`bedrooms` TINYINT UNSIGNED NOT NULL ,
INDEX ( `fkey_prop` )
);
CREATE TABLE `bathrooms` (
`fkey_prop` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT ,
`bathrooms` FLOAT UNSIGNED NOT NULL ,
INDEX ( `fkey_prop` )
);
CREATE TABLE `landscaping` (
`fkey_prop` MEDIUMINT UNSIGNED NOT NULL ,
`code` TINYINT UNSIGNED NOT NULL ,
INDEX ( `fkey_prop` )
);
So the 3 attribute tables given as examples above (bedrooms, bathrooms, and landscaping) have one-to-one and many-to-one relationships with the property table. Bedrooms and bathrooms are a simple 1-1, a home will always have one set value for number of bedrooms - it might be 4 or 2 or 3 or whatever.
However, a home could have multiple landscaping entries. Now, you'll note that the landscaping table has a field called code. Code is a numeric code for a sting which is stored in another table called 'landscape_codes'. Perhaps landscape_codes contains the values "sprinklers, grass, desert landscaping, fruit trees, chain fence, brick wall, wood fence". A home might have sprinklers and be grassy with a wooden fence. Therefore it would have 3 landscaping codes.
I want the user to be able to search homes by criteria they specify and sort by criteria they specify. They may search for "all homes containing at least 3 bedrooms that have a brick wall or chain fence".
So, I am gong to have > comparisons, < comparisons, between comparisons, and "in" statements possibly.
Also every property search will also be able to specify a timestamp range for the home. "Show me homes meeting my criteria which were added to the system between Nov 4 2003 and Nov 5 2003 AND that had a last update of Dec 28 2003"
I am trying to not do filesorts when executing the SQL query but cannot figure out a way around it. Any ideas?
Lets say I have a home which has 150 different attributes to it. Example attributes would be price, year built, square footage, number of stories, number of bedrooms, high school which home is zoned for, roofing description, or landscape description. I am making a separate table for all 150 attributes and one table to contain property numbers.
CREATE TABLE `property` (
`id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT ,
`timeadded` TIMESTAMP NOT NULL ,
`timeupdated` TIMESTAMP NOT NULL ,
PRIMARY KEY ( `id` )
);
CREATE TABLE `bedrooms` (
`fkey_prop` MEDIUMINT UNSIGNED NOT NULL ,
`bedrooms` TINYINT UNSIGNED NOT NULL ,
INDEX ( `fkey_prop` )
);
CREATE TABLE `bathrooms` (
`fkey_prop` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT ,
`bathrooms` FLOAT UNSIGNED NOT NULL ,
INDEX ( `fkey_prop` )
);
CREATE TABLE `landscaping` (
`fkey_prop` MEDIUMINT UNSIGNED NOT NULL ,
`code` TINYINT UNSIGNED NOT NULL ,
INDEX ( `fkey_prop` )
);
So the 3 attribute tables given as examples above (bedrooms, bathrooms, and landscaping) have one-to-one and many-to-one relationships with the property table. Bedrooms and bathrooms are a simple 1-1, a home will always have one set value for number of bedrooms - it might be 4 or 2 or 3 or whatever.
However, a home could have multiple landscaping entries. Now, you'll note that the landscaping table has a field called code. Code is a numeric code for a sting which is stored in another table called 'landscape_codes'. Perhaps landscape_codes contains the values "sprinklers, grass, desert landscaping, fruit trees, chain fence, brick wall, wood fence". A home might have sprinklers and be grassy with a wooden fence. Therefore it would have 3 landscaping codes.
I want the user to be able to search homes by criteria they specify and sort by criteria they specify. They may search for "all homes containing at least 3 bedrooms that have a brick wall or chain fence".
So, I am gong to have > comparisons, < comparisons, between comparisons, and "in" statements possibly.
Also every property search will also be able to specify a timestamp range for the home. "Show me homes meeting my criteria which were added to the system between Nov 4 2003 and Nov 5 2003 AND that had a last update of Dec 28 2003"
I am trying to not do filesorts when executing the SQL query but cannot figure out a way around it. Any ideas?