473,405 Members | 2,338 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,405 software developers and data experts.

need help with select and join for multiple tables

I have five tables in my database, there are actually NO common fields
between them, not even a KEY or ID or anything like that, except for
the "body" of a blob field. and that text is not identical, just a
portion of that text is identical.

each table has 5 fields, all different except the blob, which is
called "message", so normally I use something like:

select * from table1 where message like '%apple%';

to query this table, and the same goes for table 2, except the blob is
different, table 2 normally is like this:

select * from table2 where message like '%customerid=453%';

It's impossible to change the data in these fields (which would be the
best option), but there is one common element between them in the
message blob.
What I want to do is something like this:

select * from table1, table2 where message like '%order=100%';

however only one table will have that order, either table1 or table2,
but never both, and theres no way to tell which of the tables will
actually have the text.

In other words, I want to search a bunch of tables for common text
without having to actually submit the query five times, because the
list of elements to search is about 25,000 items... I'd rather submit
25,000 queries than 125,000 queries...

Yes I know its a stupid design, but it's stuck....
anyone got any workable ideas/suggestions?

B.
Jul 20 '05 #1
2 2584
Beyonder wrote:
I have five tables in my database, there are actually NO common fields
between them, not even a KEY or ID or anything like that, except for
the "body" of a blob field. and that text is not identical, just a
portion of that text is identical.
Yes I know its a stupid design, but it's stuck....
anyone got any workable ideas/suggestions?


LOL! You've got to be kidding. At this point, you might as well
uninstall MySQL and just use Perl or something to search through a bunch
of text files. You are effectively not using MySQL as a database. :-P

But I'll try to offer a constructive suggestion: since you can't change
the data, make some new data that helps you find the right records.
Create some tables that you use like a kind of custom index for the
others tables.

For instance:
CREATE TABLE table_token_idx (
table_name VARCHAR(32), # which table contains the entry
table_pk VARCHAR(32), # which row in that table
table_token VARCHAR(32), # which token was found, e.g. "customer_id"
table_value VARCHAR(32), # which customer_id value was found
)

Tip: use VARCHAR because you can't assume the customer_id or any other
value will be an integer forever. If it's textual data outside of your
control, it's almost certain that someday, someone will require the id
to contain some alpha characters or dashes or something.

Then populate the table in some offline scheduled job, by scanning
through all your text blobs and creating appropriate rows in the idx
tables. Depending on what kind of activity you expect on your blob
data, you can append to the idx table or even flush all rows and
repopulate from scratch every night.

You can then use the idx tables to search for specific order,
customerid, or whatever type of token you need to search for. Query for
a given customer_id using the idx table, and based on the results,
construct a new dynamic SQL statement that queries the correct table and
row where that customer_id is found. You have to build a new SQL
statement from scratch because you can't parameterize table names.

SELECT CONCAT('SELECT * FROM ', I.table_name, ' WHERE ID = \'',
I.table.pk, '\'')
FROM table_token_idx I
WHERE I.table_token = ? AND I.table_value = ?

Run this, supplying 'customer_id' and '453' as parameters, to use your
example. The result should be a SQL string that you can then prepare
and execute.

If you're not permitted to create new tables in this database, then
create another database, and keep the idx tables there. But you've got
to create a scaleable solution to index these data, you can't just
search it brute-force, because that will just get more expensive as the
size of the database grows.

Regards,
Bill K.

Jul 20 '05 #2
On Tue, 22 Jun 2004 16:35:53 -0700, Bill Karwin <bi**@karwin.com>
wrote:
LOL! You've got to be kidding. At this point, you might as well
uninstall MySQL and just use Perl or something to search through a bunch
of text files. You are effectively not using MySQL as a database. :-P


Thanks Bill,

actually the database is over 80 GIGS in size, and EACH query takes 30
minutes, regardless of how simple or how complex the query always
takes 30 minutes, no matter what. Yes, the hardware sucks, and the
database is HUGE.

I kinda took your following advice, I dumped the binary/master logs
for the two days in question, using mysqlbinlog and am using grep to
search through the text files.

imagine 25,000 queries at 30minutes each on the database side... yuck.
thats what? 12,500 hours or almost 520 days (about 1.5 years!) uh, no,
I dont think so... lol...

even the text grep is a bit slow, but its faster than that,uh... 7
days at best... augh!... someone please shoot me now...

B.
Jul 20 '05 #3

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

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
1
by: TeleTech1212 | last post by:
I am trying to select specific columns from multiple tables based on a common identifier found in each table. For example, the three tables: PUBACC_AC PUBACC_AM PUBACC_AN each have a...
6
by: Eric Robinson | last post by:
Hi all, I'm having real trouble wrapping my newbie brain around this problem. Can someone please tell me the most efficient (or any!) way to write a SELECT statement to return a set of rows from...
7
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
2
by: orenlevy1 | last post by:
Hi Everyone. I have a problem that I could not figure out what to do with it. I have a couple of tables and views. All have the same unique ID. When a user try to do a search on our web site...
0
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in...
1
by: dharmu131983 | last post by:
Hi, i have 2 tables A & C but i dont have any column common to join them. so i am using a 2nd table say B from my data base and using that i am joing A and C. I want only distinct Values from the...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.