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

LEFT JOIN limitations ??

Hello,
I have a strange problem, maybe some of you will be able to explain me
something. I use LEFT JOIN as a substitute for subselects. It's true
that many subselects can be rewriten using LEFT JOIN. I have made a
query which use LEFT JOIN statement and... when there are many LEFT
JOIN's (over 3) on the same table MySQL execute this query very long
time... few hours or more. Maybe there is something wrong with my table
structures... Are there any limitations for LEFT JOIN ??

Below the query, and table structures...

-- QUERY

SELECT
DISTINCT
_NEW.news_id,
_NNA.title,
IF(LENGTH(_NNA.content) > 250, CONCAT(SUBSTRING(_NNA.content, 1,
250),'...'), _NNA.content) AS content,
_NEW.publish_date
FROM
new_news _NEW,
new_news_names_search _NNA
LEFT JOIN new_news_categorys _CAT21 ON _CAT21.news_id = _NEW.news_id
AND _CAT21.category_id IN (21)
LEFT JOIN new_news_categorys _CAT18 ON _CAT18.news_id = _NEW.news_id
AND _CAT18.category_id IN (18)
LEFT JOIN new_news_categorys _CAT50 ON _CAT50.news_id = _NEW.news_id
AND _CAT50.category_id IN (50)
LEFT JOIN new_news_categorys _CAT1 ON _CAT1.news_id = _NEW.news_id AND
_CAT1.category_id IN (1,2,3,17,19,30,37)
WHERE
_NEW.publish_date <= NOW() AND
_NNA.news_id = _NEW.news_id AND
_NNA.language_id = '1' AND
_CAT21.news_id > 0 AND
_CAT18.news_id > 0 AND
_CAT50.news_id > 0 AND
_CAT1.news_id > 0
ORDER BY
_NEW.publish_date DESC
#
# Table structure for table 'new_news_categorys'
#

CREATE TABLE new_news_categorys (
news_id int(10) NOT NULL default '0',
category_id int(10) NOT NULL default '0',
PRIMARY KEY (news_id,category_id),
KEY category_id (category_id),
CONSTRAINT 0_1901 FOREIGN KEY (news_id) REFERENCES new_news (news_id)
ON DELETE CASCADE,
CONSTRAINT 0_1902 FOREIGN KEY (category_id) REFERENCES
set_new_news_categorys (category_id) ON DELETE CASCADE
) TYPE=InnoDB;

#
# Table structure for table 'new_news_names'
#

CREATE TABLE new_news_names (
news_id int(10) NOT NULL default '0',
language_id int(10) NOT NULL default '0',
title longtext,
content longtext,
PRIMARY KEY (news_id,language_id),
KEY news_id (news_id),
KEY language_id (language_id),
CONSTRAINT 0_1909 FOREIGN KEY (news_id) REFERENCES new_news (news_id)
ON DELETE CASCADE
) TYPE=InnoDB;

#
# Table structure for table 'new_news_names_search'
#

CREATE TABLE new_news_names_search (
news_id int(11) NOT NULL default '0',
language_id int(11) NOT NULL default '0',
title longtext,
content longtext,
PRIMARY KEY (news_id,language_id),
FULLTEXT KEY title (title,content)
) TYPE=MyISAM;

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/my***********...ie.nctu.edu.tw

Jul 19 '05 #1
0 1477

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

Similar topics

0
by: Marek Lewczuk | last post by:
Hello, I have a strange problem, maybe some of you will be able to explain me something. I use LEFT JOIN as a substitute for subselects. It's true that many subselects can be rewriten using LEFT...
0
by: Petre Agenbag | last post by:
Hi List Me again. I'm trying to return from multiple tables, the records that have field "information_sent" between two dates. The tables are all related by means of the id of the entry in the...
0
by: Soefara | last post by:
Dear Sirs, I am experiencing strange results when trying to optimize a LEFT JOIN on 3 tables using MySQL. Given 3 tables A, B, C such as the following: create table A ( uniqueId int not...
1
by: Paul Bramscher | last post by:
Here's one for pathological SQL programmers. I've got a table of things called elements. They're components, sort of like amino acids, which come together to form complex web pages -- as nodes...
4
by: jbm05 | last post by:
Hi, I'm curious about the computational complexity of a query I have. The query contains multiple nested self left joins, starting with a simple select, then doing a self left join with the...
3
by: Dam | last post by:
Using SqlServer : Query 1 : SELECT def.lID as IdDefinition, TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour FROM serveur.Data_tblDEFINITIONTABLEDECODES def,...
3
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but...
14
by: mike | last post by:
I'm using postgresl 7.3.2 and have a query that executes very slowly. There are 2 tables: Item and LogEvent. ItemID (an int4) is the primary key of Item, and is also a field in LogEvent. Some...
2
by: tricard | last post by:
Good day all, I have a large outer joined query that I want to have some criteria. The select query is gathering all part numbers from tblPartNumbers, left joining to tblPartNumberVendor (since...
1
by: naveenchhibber | last post by:
Hi all pls tell me that the following statment is valid in oracle 9i or 10g.. update ws set received_by_facility = coalesce(rbf_ouk.organizational_unit_id, 0), ...
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: 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
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
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...

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.