473,396 Members | 1,849 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,396 software developers and data experts.

query optimization help please

hello,
i have a database where there is a main table, documents, and then a
relationship table doc_topics with one entry for each topic into which
a document falls. (any document may have an arbitrary number of
topics, but always at least one.) this structure is repeated for other
relationships such as doc_states, doc_types, et cetera. i want a query
that uses one or more of the relationships as search criteria (example,
return only documents with a doc_state entry of "NY"), but i need the
query to return ALL of the states that document pertains to. my
version of mysql does not support subqueries or exist clauses. a
sample query is

select distinct *, t2.topic_id as tid, t2.topic_desc as tdsc from
cap_documents d, cap_doc_topics dt, cap_topics t, cap_doc_states ds
left join cap_doc_topics dt2 on dt2.doc_id = d.doc_id left join
cap_topics t2 on t2.topic_id = dt2.topic_id left join cap_doc_states
ds2 on ds2.doc_id = d.doc_id where d.doc_id = dt.doc_id and dt.topic_id
= t.topic_id and d.doc_id = dt2.doc_id and d.doc_id = ds.doc_id and
d.doc_id = ds2.doc_id and d.display='Y' and match(d.doc_title,
d.summary, t.topic_desc) against('medicare* ' IN BOOLEAN MODE) order by
doc_year desc, d.doc_year desc, d.doc_title, d.author,
d.author_first_name

however, this query takes ten seconds or more to execute. output of
explain is as follows:

+-------+--------+-------------------------+---------+---------+--------------+------+----------------------------------------------+
| table | type | possible_keys | key | key_len | ref
| rows | Extra |
+-------+--------+-------------------------+---------+---------+--------------+------+----------------------------------------------+
| d | ref | PRIMARY,display | display | 1 | const
| 51 | Using where; Using temporary; Using filesort |
| ds | ref | PRIMARY,doc_id | PRIMARY | 8 |
d.doc_id | 1 | Using index |
| ds2 | ref | PRIMARY,doc_id | PRIMARY | 8 |
d.doc_id | 1 | Using where; Using index |
| dt | ref | PRIMARY,doc_id,topic_id | PRIMARY | 8 |
d.doc_id | 3 | Using index |
| dt2 | ref | PRIMARY,doc_id | PRIMARY | 8 |
d.doc_id | 3 | Using where; Using index |
| t2 | eq_ref | PRIMARY | PRIMARY | 8 |
dt2.topic_id | 1 | |
| t | eq_ref | PRIMARY | PRIMARY | 8 |
dt.topic_id | 1 | Using where |
+-------+--------+-------------------------+---------+---------+--------------+------+----------------------------------------------

i have indices in place, and all the join fields are the same type and
size in each table.

any help PLEASE ?

thanks,
-k

Oct 13 '06 #1
0 1978

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

Similar topics

2
by: ensnare | last post by:
This query is running REAL slow ... like 1.2 secs ... any ideas on how I could optimize it? Perhaps my indexes are incorrect? $this->query = "SELECT m.username as username, e.title as title,...
5
by: AC Slater | last post by:
Whats the simplest way to change a single stored procedures query optimization level? In UDB8 that is. /F
1
by: Sean C. | last post by:
Helpful folks, I have recently migrated our test server, which runs Win NT 4, from V7.2 FP11 to V8.1.3. Just about everything works wondefully, except I am having major problems getting the...
2
by: Eugene | last post by:
I am trying to set query optimization class in a simple SQL UDF like this: CREATE FUNCTION udftest ( in_item_id INT ) SPECIFIC udftest MODIFIES SQL DATA RETURNS TABLE( location_id INT,...
12
by: WantedToBeDBA | last post by:
Hi all, db2 => create table emp(empno int not null primary key, \ db2 (cont.) => sex char(1) not null constraint s_check check \ db2 (cont.) => (sex in ('m','f')) \ db2 (cont.) => not enforced...
11
by: 73blazer | last post by:
We are migrating a customer from Version 7.1 FP3, to Version 8.2 (8.1 FP8). For the most part, things are faster, but there is one query that is much much slower, and it is a query that is used all...
6
by: UnixSlaxer | last post by:
Hello, Running a query for the first time on DB2 takes a fixed amount of time. But when query is executed for the second time, the amount of time is usually less since the query is (most...
4
by: Bernard Dhooghe | last post by:
To retrieve data from a query where multiple rows can be returned, a cursor can be used. Different programming interface exist for cursors: embedded SQL, CLI, SQL PL, SQLJ, JDBC. I we look at...
29
by: wizofaus | last post by:
I previously posted about a problem where it seemed that changing the case of the word "BY" in a SELECT query was causing it to run much much faster. Now I've hit the same thing again, where...
0
ADezii
by: ADezii | last post by:
One frequently asked question at TheScripts is "Should I use a Stored Query or an SQL Statement in those situations that require a Query (RecordSets, RecordSources, Append, Delete, Update Operations,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.