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

Optimize this!

Please help me optimize this:

I have a table with columns: headlineid, keyword.
headlineid+keyword combination is unique.

Relationship between headline and keyword is many-to-many. i.e.,
headlines can have many keywords. keywords can be associated with many
headlines.

Keywords in the same headline are considered "related".

Here's the query to find out which keywords 'hello' is related to and
sort desc on number of occurrences of the related keywords:

select keyword, count(keyword) as keywordcount from tags where
headlineid in (select distinct(headlineid) from tags where keyword =
'hello') AND keyword <'hello' group by keyword order by keywordcount
desc limit 0, 5;

This query takes a lot of time. Need help with optimization. All help
is appreciated.

Dec 19 '06 #1
1 2423

ra**********@gmail.com wrote:
Please help me optimize this:

I have a table with columns: headlineid, keyword.
headlineid+keyword combination is unique.

Relationship between headline and keyword is many-to-many. i.e.,
headlines can have many keywords. keywords can be associated with many
headlines.

Keywords in the same headline are considered "related".

Here's the query to find out which keywords 'hello' is related to and
sort desc on number of occurrences of the related keywords:

select keyword, count(keyword) as keywordcount from tags where
headlineid in (select distinct(headlineid) from tags where keyword =
'hello') AND keyword <'hello' group by keyword order by keywordcount
desc limit 0, 5;

This query takes a lot of time. Need help with optimization. All help
is appreciated.
Try turning it into a join (example below), this usually helps speed up
this sort of thing.
Also build 2 indexes, one beginning with keyword the other beginning
with headlineid.

SELECT t2.keyword, count( t2.keyword ) AS keywordcount
FROM tags t1
JOIN tags t2 ON t1.headlineid = t2.headlineid AND t2.keyword <'hello'
WHERE t1.keyword = 'hello'
GROUP BY keyword
ORDER BY keywordcount DESC
LIMIT 0 , 5;

Dec 19 '06 #2

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

Similar topics

0
by: Tom Paquette | last post by:
Hi, Having made very good use of the ADO recordset Field indexes created by setting the Optimize property, I am thrashing through ADO.Net literature to identify the same functionality. Being...
0
by: Andreas Falck | last post by:
Hi, I ran the code below on two different versions, 4.0.14 and 4.0.16 respectively, both running RH 7.3 on intel. In version mysql server version 4.0.14 the SELECT privelege suffices for...
0
by: Daniel | last post by:
Hi there, I recently came across an interesting option when right clicking on a project (Right click on the project -> properties -> Configuration Properties ->Build -> Optimize) There is an...
6
by: Silly | last post by:
byte Name = new byte; uint len = (uint)Name.Length; uint err = MyFunction(devID, out Name, out len); When this code is run in release build with optimize code set to true, len is evaluated to...
3
by: Reddy | last post by:
The sql query for my datagrid returns 100, 000 records. But the datagrid should display 20 records per page. I am using datagrid paging, but it is taking too much time for the page to load. Is...
3
by: Sonnich | last post by:
While trying to shorten my files, I tried optimize table - later I found that I need: mysqlcheck -u root -p[password[ --all-databases --analyze --optimize (thanks to Markus Popp). But it...
4
by: Huaer.XC | last post by:
>From the following MySQL command: EXPLAIN SELECT * FROM t1 JOIN t2 ON (t1.id = t2.id) JOIN t3 ON t3.name = t1.name WHERE t1.id IN(123, 124); which result is:...
15
by: kenneth | last post by:
I was trying to use multiple thread to optimize my following code, but met some problems, anyone can help me? k are initialized. int computePot() { int i, j; for( i=0; i<500; i++ ) { for(...
14
by: andreyvul | last post by:
I have this loop (all variables are pointers): for (foo = bar; foo baz; foo--) *(foo+1) = *foo; How do I optimize the pointer swap so that it uses -- and ++ or unary +- instead of +1 (if possible...
2
by: pavanip | last post by:
Hi, I have an application like Optimize System Performance by using Memory speed, cpu speed and Disk speed. How to optimize memory speed,disk optimization and CPU optimization. Please provide me...
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: 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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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: 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
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...

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.