If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Attribute search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-08-10, 08:18
krontrex krontrex is offline
Registered User
 
Join Date: Sep 2010
Posts: 37
Attribute search

Hi,
I have a following problem, I have an object that represents a person, member of a team. The attributes are name, last name, age, sex, education, city of birth, profession, etc.). Now, I would like to make a query that relates only to attributes without requiring actually information about person. For example, I would like to find out of what professions are male members, older than 35 years and born in New York. I can make query that indirectly searches through relative attributes of all persons but it is inefficient because there is lot of redundancy involved. Is there any way to optimize this kind of search?
Thank you
Reply With Quote
  #2 (permalink)  
Old 10-08-10, 08:30
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by krontrex View Post
...but it is inefficient because there is lot of redundancy involved.
redundancy? what redundancy?

optimization is accomplished with indexes on columns, and will work only if the query requires some meaningful restriction of values in that column

for instance, your query "what professions are male members, older than 35 years and born in New York" might use an index on city or on age, but likely not sex (because of low cardinality)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-08-10, 08:31
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
What's inefficient?
Code:
SELECT profession
FROM people
WHERE sex = 'M'
AND age > 35
AND city = 'NY'
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #4 (permalink)  
Old 10-08-10, 08:44
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Quote:
Originally Posted by pootle flump View Post
What's inefficient?
Code:
SELECT profession
FROM people
WHERE sex = 'M'
AND age > 35
AND city = 'NY'
SELECT DISTINCT profession ...
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #5 (permalink)  
Old 10-08-10, 08:46
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
I do hope we're not dealing with an EAV model here:
Code:
insert into person_attributes (person_id, att_name, att_value)
values (123, 'Name', 'Smith');
insert into person_attributes (person_id, att_name, att_value)
values (123, 'Sex', 'Male');
insert into person_attributes (person_id, att_name, att_value)
values (123, 'DOB', '01-JAN-1970');
(It is the talk of objects and attributes that makes me fear we may be...)
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #6 (permalink)  
Old 10-08-10, 09:14
krontrex krontrex is offline
Registered User
 
Join Date: Sep 2010
Posts: 37
redundancy

Thanks for the answers.
It is not an EAV model.
I meant by redundancy there may be many people of same profession that satisfy the query, is there any way to group them on the basis of their profession and after finding the first member to exempt rest of them from the search.
Reply With Quote
  #7 (permalink)  
Old 10-08-10, 09:20
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
post #3, with the correction in post #4.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #8 (permalink)  
Old 10-09-10, 04:34
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Quote:
Originally Posted by krontrex View Post
Thanks for the answers.
It is not an EAV model.
I meant by redundancy there may be many people of same profession that satisfy the query, is there any way to group them on the basis of their profession and after finding the first member to exempt rest of them from the search.
I'm glad it isn't EAV

I think you are trying to optimise on behalf of the database here: that's not the way a relational database works, or it least it shouldn't be. You just "declaratively" specify the result you want, which as Pootle says is:
Code:
SELECT DISTINCT profession
FROM people
WHERE sex = 'M'
AND age > 35
AND city = 'NY'
and then the database figures out the most efficient way to answer that question.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Tags
attributes, query, redundancy

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On