473,379 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Advanced Select Problem - Please Help

I hope someone can help me with this one. For performance reasons, I have a
denormalized database. There are two tables in the database we can call
them table a and table b. Both of theses tables contain columns that are
text with comma seperated values.

example:

TABLE A
----------
id - integer - primary key
column1 - text
column3 - text
column4 - text

SAMPLE RECORDS FOR TABLE A
id: 1
column1 : vanilla, chocolate chip, black raspberry
column2 : palm handheld
column3 : oldsmobile alero, chevy corvette, toyota camery
column4 : new jersey, nevada, wyoming, texas, new mexico

id: 2
column1 : vanilla, strawberry
column2 : dell laptop, palm handheld
column3: toyota camery
column4 : ohio, alaska, hawaii
TABLE B
----------
id - integer - primary key
column1 - text
column3 - text
column4 - text

SAMPLE RECORD FOR TABLE B
id: 15
column1 : vanilla, chocolate chip, black raspberry, butter pecan
column2 : dell laptop, hp desktop, palm handheld
column3 : honda civic, chevy corvette, toyota camery
column4 : texas, new mexico, florida


What I need is to create a select statement that returns the id's for table
a that have at least one data value match in every column in table b.

The above example would return the id of 1 from table one because :

column1 matches on: vanilla and chocolate chip and black raspberry
column2 matches on: palm handheld
column3 matches on: chevy corvette and toyota camery
column4 matches on: texas and new mexico

id 2 would not be returned because there are no matches on column 4
The problem is that I am running MySQL version 3.23.58 so I can't use
subqueries or boolean match against commands.

Can anyone think of away to do this without creating a select statment that
has a million LIKE %___%

Thanks.

Sep 13 '05 #1
5 1473
"MJunium" <mj*****@recruitingnevada.com> wrote in message
news:QyHVe.11$2o.3@fed1read05...
I hope someone can help me with this one. For performance reasons, I have

a denormalized database. ....
<snip>

Please clarify this.

If the database is deliberately denormalized, there are only 2 reasons I can
think of. Either -
A) You don't understand database normalization.
B) You want the system to perform as poorly as possible.

If neither applies, then you should certainly consider abandoning the use of
a relational database system like MySQL and opt, instead, for a system
designed from the ground up to work with "denormalized" databases.

But

If it is B - I can show you some really bad queries consistent with your
stated design goal.
Thomas Bartkus
Sep 14 '05 #2
When I say denormalized - I mean it is not normalized out to 3rd normal
form.

Sep 14 '05 #3
On 14/09/2005, Mark wrote:
When I say denormalized - I mean it is not normalized out to 3rd
normal form.


It isn't even in 1NF.

--
felix
Sep 14 '05 #4
MJunium wrote:
I hope someone can help me with this one. For performance reasons, I have a
denormalized database.


How did you measure the performance that leads you to believe that
storing it in this non-normalized form has a benefit? How much of a
benefit?

What I'm getting at is that many software engineers _assume_ that
they'll get a performance benefit by doing something, without actually
measuring it to see if that assumption is true, or how much of a
benefit/penalty there is relative to other techniques. Statements like
"it's obvious that..." or "it stands to reason that..." are the same as
making an assumption, unless you have performance measurements to
support the statement.

So if you get a 0.0001% performance gain, but it takes 2000% more code
complexity to achieve, is that worth the tradeoff? If not, bring those
two values closer together. At what threshold is it worth the tradeoff?
Does your given case fall within this threshold?

The correct way to do the problem you're describing is to normalize
those values. Define a separate table for each of column1...column4.

For instance:
CREATE TABLE flavors (
a_id integer references table_a(id),
flavor varchar(64),
primary key (a_id, flavor)
);

Do the same for table b.
Now you can find the matches as follows:

SELECT DISTINCT a.id
FROM table_a AS a
INNER JOIN flavors AS f ON a.id = f.a_id
INNER JOIN computers AS c ON a.id = c.a_id
INNER JOIN table_b AS b
INNER JOIN b_flavors AS bf ON (b.id = bf.b_id AND f.flavor = bf.flavor)
INNER JOIN b_computers AS bc ON (b.id = bc.b_id AND c.computer =
bc.computer)
WHERE b.id = 15

I predict that a join like this actually performs much better than the
huge expressions that would be required by the denormalized design.

Regards,
Bill K.
Sep 14 '05 #5
You hit the nail on the head with the code vs performance gain. The
reason this was not normalized is that there are more like 15 different
columns not just the 4. The query time to do all the table joins was
unacceptable.

Sep 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Cengiz Ulku | last post by:
Hi, I know now, how to search for a special char. or a word in a RTB control. But, my question is: My RTF file is some sort of an index document, there are chapter numbers and within these...
6
by: Pedro Fonseca | last post by:
Greetings! Can someone please help me to crack this problem? I have 4 tables: Subject, Forum, Topic and Post. A Subject groups various Forums, a Forum groups various Topics, and a Topic groups...
0
by: Ryan | last post by:
Hello. I am working on an OLAP tutorial for Data Analysis in SQL Server 2000. I have worked through nearly 2 full tutorials and came across a problem. When trying to create a Parent-Child Dimension...
2
by: devpoint | last post by:
Advanced DHTML Dropdown List component (Javascript,ASP,.NET,PHP) enhances usability of large dropdown lists with type & select feature. It suggests possible matches for entries you type in the...
4
by: ianv2 | last post by:
Hi I have the following form that I need advanced validation on, I would appreciate any help please. How can I validate the form so that the user has to select an option from the select box...
2
by: Brad Shook | last post by:
First of all thinks to Cor Ligthert for helping me with this last week. If you wild like to read Cor's comments please refer to the posting from 10/14/2004 and 8:48AM "Help with Advanced...
1
by: Monty | last post by:
I'm having trouble updating records. I get an error saying my update command has not been set. I realize I need to enable both options in the "Advanced SQL Generation Options" screen, but these...
0
by: gderosa | last post by:
I have searched for hours regarding this but I am trying to make an advanced search page for my application that has drop downs for 'Greater Than', 'Equals', 'Less Than'. For example the search page...
1
by: mbatestblrock | last post by:
I think I have a rather advanced question that I was hoping to find some good help with. I am still pretty new to VBA and I know that doesn't help my situation here. But here is what I am trying to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.