473,795 Members | 3,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1528
"MJunium" <mj*****@recrui tingnevada.com> wrote in message
news:QyHVe.11$2 o.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 "denormaliz ed" 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...colum n4.

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
2638
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 chapters, each line is also numbered. For to avoid ambigous numbers each chapter number is "Bold, 14pts" and each line is "Bold, superscript, 9pts". (Remark: I can not use letters instead of numbers).
6
3198
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 several Posts. The references inside the tables are: +-----------+ +-----------+ +-----------+ +-----------+ | Subject | | Forum | | Topic | | Post | +-----------+ +-----------+ +-----------+ +-----------+
0
1242
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 with the wizard, I select the tutorial file and click Next. On the Select Advanced Options step there is no Writeback option available. The only options I have are: Custom Rollups, Members with data, and Ordering and uniqueness of members. When...
2
3305
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 input box. Works in all browser with DIV, CSS and JavaScript support: IE5+, Netscape6+, Mozilla, Opera. The script allows full customization with style sheets, single and multiple select mode. Web site: http://195.228.204.9/advsel/
4
1553
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 and if they choose 'other' the focus goes to the 'otherfeedback' textarea which also has to have a value. <form action="feedback.cfm" method="post" name="form" id="Form"
2
1323
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 Datagrid" I am trying to bind one column of a datagrid to a seperate textbox and the rest of the fields to a datagrid. the comments are too large to fit in a datagrid so I created a textbox below the datagrid and need it to hold the data for the...
1
1729
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 options are dimmed such that I cannot select them. Any help please. Thank you, Mark
0
1354
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 needs to be like this: ENDDATE: How can I manipulate the SQL search string to change the value when the user selects a search criteria in the dropdown? At the moment it is SELECT * FROM Table WHERE EndDate LIKE TextBox1% I would like...
1
1438
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 accomplish. I have a relatively simple database. The main points are which I have a Form with a sub form in it. This form is a customer form and the main part of the form has their name address and phone number. The sub form has sales...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10436
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.