I need help on a query.
There is a common titles database for several radio stations
Some titles are enabled and some are not enabled for each station.
Example of some tables:
Titles Stations Station_Titles
------ -------- -------------
id id Station_ID
Title StationName Title_ID
Enabled
I want to display all the titles of stationID = 1 and Enabled = "Y"
(In the query there are some other joins for album, artist etc.)
The problem is that the query I use takes more than a minute to get the
results for 1000 titles. Whithout this join it takes only 2 seconds to
get 2000 records.
this query takes .5 sec to execute :
select a.name as artist_name, a.id as artist_id, b.title as album_title,
b.id as album_id,
t.* from category_titles ct
inner join titles t on ct.title_id = t.id
left join artists a on t.artist_id = a.id
left join albums b on t.album_id = b.id
where ct.category_id is not null
group by a.name, t.title
but the complete Query :
select a.name as artist_name, a.id as artist_id, b.title as
album_title,
b.id as album_id,
t.* from category_titles ct
inner join titles t on ct.title_id = t.id
left join artists a on t.artist_id = a.id
left join albums b on t.album_id = b.id
inner join station_titles st on t.id = st.title_id and st.station_id =
1 and st.enabled = "Y"
where ct.category_id is not null
group by a.name, t.title
takes 1 minute for 1000 records
any suggestions on how to improve performance of the query ? 7 1688
Jim wrote: I need help on a query. There is a common titles database for several radio stations Some titles are enabled and some are not enabled for each station.
Example of some tables:
Titles Stations Station_Titles ------ -------- ------------- id id Station_ID Title StationName Title_ID Enabled
I want to display all the titles of stationID = 1 and Enabled = "Y"
(In the query there are some other joins for album, artist etc.) The problem is that the query I use takes more than a minute to get the results for 1000 titles. Whithout this join it takes only 2 seconds to get 2000 records.
this query takes .5 sec to execute :
select a.name as artist_name, a.id as artist_id, b.title as album_title, b.id as album_id, t.* from category_titles ct inner join titles t on ct.title_id = t.id left join artists a on t.artist_id = a.id left join albums b on t.album_id = b.id where ct.category_id is not null group by a.name, t.title
but the complete Query :
select a.name as artist_name, a.id as artist_id, b.title as album_title, b.id as album_id, t.* from category_titles ct inner join titles t on ct.title_id = t.id left join artists a on t.artist_id = a.id left join albums b on t.album_id = b.id inner join station_titles st on t.id = st.title_id and st.station_id = 1 and st.enabled = "Y" where ct.category_id is not null group by a.name, t.title
takes 1 minute for 1000 records
any suggestions on how to improve performance of the query ?
You don't mention the schema - are you using indexes? http://dev.mysql.com/doc/mysql/en/MySQL_indexes.html http://dev.mysql.com/doc/mysql/en/LE...imization.html
and http://dev.mysql.com/doc/mysql/en/Query_Speed.html
--
Tony
Jim wrote: select a.name as artist_name, a.id as artist_id, b.title as album_title, b.id as album_id, t.* from category_titles ct inner join titles t on ct.title_id = t.id left join artists a on t.artist_id = a.id left join albums b on t.album_id = b.id inner join station_titles st on t.id = st.title_id and st.station_id = 1 and st.enabled = "Y"
You should make sure that an index exists for each of the columns,
st.title_id, st.station_id and st.enabled.
Also, it's a bit confusing that you are putting row restriction
conditions in your 'ON' clause here, instead of putting them in the
'WHERE' clause below. The result is the same in the case of your query,
but it's worthwhile to develop a distinction between join conditions and
row restriction conditions, because sometimes it matters (for example,
in outer joins).
where ct.category_id is not null group by a.name, t.title
For what it's worth, I think you're using 'group by' when you mean
'order by'. They achieve the same thing in this case (sorting the
result), but only by coincedence.
takes 1 minute for 1000 records
any suggestions on how to improve performance of the query ?
The usual easy suggestions are to examine the output of EXPLAIN for your
query, and make sure you have indexes on the columns that you're using
for sorting, join conditions, and row restriction conditions.
Regards,
Bill K.
"Jim" <ir******@NOSPA Mhotmail.com> wrote in message
news:1104249219 .19435@athnrd02 ... I need help on a query. There is a common titles database for several radio stations Some titles are enabled and some are not enabled for each station.
Example of some tables:
Titles Stations Station_Titles ------ -------- ------------- id id Station_ID Title StationName Title_ID Enabled
I want to display all the titles of stationID = 1 and Enabled = "Y"
(In the query there are some other joins for album, artist etc.) The problem is that the query I use takes more than a minute to get the results for 1000 titles. Whithout this join it takes only 2 seconds to get 2000 records.
this query takes .5 sec to execute :
select a.name as artist_name, a.id as artist_id, b.title as album_title, b.id as album_id, t.* from category_titles ct inner join titles t on ct.title_id = t.id left join artists a on t.artist_id = a.id left join albums b on t.album_id = b.id where ct.category_id is not null group by a.name, t.title
but the complete Query :
select a.name as artist_name, a.id as artist_id, b.title as album_title, b.id as album_id, t.* from category_titles ct inner join titles t on ct.title_id = t.id left join artists a on t.artist_id = a.id left join albums b on t.album_id = b.id inner join station_titles st on t.id = st.title_id and st.station_id = 1 and st.enabled = "Y" where ct.category_id is not null group by a.name, t.title
takes 1 minute for 1000 records
any suggestions on how to improve performance of the query ?
I'd be happy to give it a shot. Please post your create table statements and
if possible some sample data.
Regards,
Rich
In fact in table "station_titles " I do not use indexes :(
the create statements are as follows :
CREATE TABLE `albums` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`artist_id` int(11) NOT NULL default 0,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_album_arti st` (`title`,`artis t_id`)
) TYPE=MyISAM;
CREATE TABLE `artists` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL default '',
`repeat` int(11) NOT NULL default 0,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_artist_nam e` (`name`)
) TYPE=MyISAM;
CREATE TABLE `titles` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
/* some other fields */
`full_path` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;
CREATE TABLE `category_title s` (
`id` int(11) NOT NULL auto_increment,
`category_id` int(11) NOT NULL default 0,
`title_id` int(11) NOT NULL default 0,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_cat_title` (`category_id`, `title_id`)
) TYPE=MyISAM;
CREATE TABLE `station_titles ` (
`station_id` int(11) NOT NULL default 0,
`title_id` int(11) NOT NULL default 0,
`enabled` enum('Y','N') NOT NULL default 'Y'
) TYPE=MyISAM;
what other indexes do you think I should create ?
"Jim" <ir******@NOSPA Mhotmail.com> wrote in message
news:1104249219 .19435@athnrd02 ... I need help on a query. There is a common titles database for several radio stations Some titles are enabled and some are not enabled for each station.<
Hi Jim,
I've recreated your database and have loaded sample data, However, you
queries will not work because table Titles is missing some columns (i.e
artist_id?). What other columns are in this table? Also, what is the
relationship between Titles and Albums?
Regards,
Rich
You are right. I forgot some fields. Here you are:
CREATE TABLE `titles` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`artist_id` int(11) NOT NULL default 0,
`album_id` int(11) NOT NULL default 0,
`tempo_id` int(11) NOT NULL default 0,
`mood_id` int(11) NOT NULL default 0,
`Rating_id` int(11) NOT NULL default 0,
`full_path` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;
There are some other tables for Mood, Tempo, Rating that are all like :
CREATE TABLE `moods` (
`id` int(11) NOT NULL,
`info` varchar(255) default NULL,
`Color` int(11) default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;
The relation between Albums and Titles is by field "album_id" I forgot
to include in my previous post.
Finaly I added an index to "station_titles " and the query is now fast
enough.
I 'll try to load about 50000 titles to database to test the
performance.
Thanks
Rich
I sent you by email a sample database to test This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: James |
last post by:
My form and results are on one page.
If I use :
if ($Company) {
$query = "Select Company, Contact
From tblworking
Where ID = $Company
Order By Company ASC";
}
|
by: netpurpose |
last post by:
I need to extract data from this table to find the lowest prices of
each product as of today. The product will be listed/grouped by the
name only, discarding the product code - I use SUBSTRING(ProductName,
1, CHARINDEX('(', ProductName)-2).
I can get this result, but I had to use several views (totally
inefficient). I think this can be done in one efficient/fast query,
but I can't think of one.
In the case that one query is not...
|
by: Dom Boyce |
last post by:
Hi
First up, I am using MS Access 2002.
I have a database which records analyst rating changes for a list of
companies on a daily basis. Unfortunately, the database has been set
up (by my predecessor, I hasten to add) so that each day it creates a
copy of the record for each company, changes the date to today's date,
and prompts the user for any changes of ratings on that day. The
resulting data table grows by approx 600 records per...
|
by: Andrew McNab |
last post by:
Hi folks,
I have a problem with an MS Access SQL query which is being used in an
Access Report, and am wondering if anyone can help.
Basically, my query (shown below) gets some records from a couple of
tables in my database using INNER JOINS and the WHERE clause to
specify the required constraints. However, I also want to read two
fields from a *single* record from a table called 'Locations' and then
apply one of these field's values...
|
by: Steve Patrick |
last post by:
Hi All
You guys are my last hope, despite spending money on books and hours reading
them I still can not achieve the results I need.
I have designed a database in Access 2000 based on 1 table, all has gone
very well with one exception. The table is based on applications made by
potential customers looking to buy franchise rights to particular locations
and as part of the process they are asked to list their preferred locations
1 to 4....
| |
by: Alan Lane |
last post by:
Hello world:
I'm including both code and examples of query output. I appologize if
that makes this message longer than it should be.
Anyway, I need to change the query below into a pivot table query. I'm
having trouble doing it. Help!
Here is my code so far:
Sub OldRegionQuery()
|
by: Takeadoe |
last post by:
Dear NG,
Can someone assist me with writing the little code that is needed to
run an update table query each time the database is opened? From what
I've been able to glean from this group, the Autoexec Macro looks like
the way to go. Could someone please assist?
Thank you very much!
Mike
|
by: mcmahonb |
last post by:
Hey people...
I've been searching this forum for a few hours and even though this topic has been went over from many different angles; I cannot seem to figure out how to make things work on my side.
I am trying to learn how to manipulate Dynamic Queries by forms via the example database: QrySampl.MDB, offered by Microsoft (as a learning tool, I suppose.) In particular, I am working with code from the example: "Query By Form (QBF) Using...
|
by: n |
last post by:
Hello! Here is a problem I hope you can point me to a solution. It
Problem: A teacher needs to know which lesson to teach.
A school has a curriculum with 26 lessons, A-Z.
For a given class, a random number of students arrive, each of which
has completed a random number of lessons taken at random from the
curriculum.
|
by: Jo |
last post by:
Hi there,
I'm Jo and it's the first time I've posted here. I'm in process of creating
a database at work and have come a little unstuck.....I'm a bit of a novice
and wondered if anyone could help. I work in a library and send out dual
language books to babies of dual or other nationality.
The db is to be used for logging a range of book titles and numbers ordered
and books sent out to individuals. I am trying to work out a way of...
|
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...
| |
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...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |