473,725 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Building a news management system (full story)

Hi groupies

I'm building a news site, to wich a user can add new items into a mySQL
db.
It's still in testfase, but it's so extremely slow, i want to figure
out what i'm doing wrong, or what to change before it goes live ...
I know it's quite a long story, but i would be so happy if anyone could
help me out here ...
I've read on optimizing DB structure etc, but still cannot speed things
up ...

(Hope Google doesn't mess up the lines too much ... )

There are 4 relevant tables (yet) in the site:
1. ne_topics
2. ne_fulltopic
3. ne_comments
4. gl_users

*************** *************** *************** *************** *************** *

Table 1: ne_topics
id (int 11)
author_id (int 11) // user's id of whom created it.
creation (datetime) // datetime when item was created
publication (datetime) // datetime when item is (to be) published
title (varchar 35) // title of the item
url (varchar 35) // url of the item, anything a-z, 0-9, -
and _
body (text) // body text of item, including some
BBcodes
visible (tinyint 1) // is item visible or not ( 1 or 0 )
sticky (tinyint 1) // sticky or not ( 1 or 0 )

++ Currently 99.977 testrows, puplication dates random between 1-1-2000
and 31-12-2009, 60,1 MB of data,
id is PRIMARY
publication, url are UNIQUE
visible has INDEX

*************** *************** *************** *************** *************** *

Table 2: ne_fulltopic
id (int 11) // matches ne_topic.id, foreign keys not
available
fullbody (text) // contains an extended version of news

++ Currently 1 testrow, 2.904 Bytes of data,
id is PRIMARY

*************** *************** *************** *************** *************** *

Table 3: ne_comments
id (int 11)
topic_id (int 11) // to wich item does this comment belong
author_id (int 11) // user's id of whom created it.
comment (text) // comment of the user, including some
BBcodes

++ Currently 1 testrow, 4.124 Bytesof data,
id is PRIMARY
topic_id has INDEX

*************** *************** *************** *************** *************** *

Table 4: gl_users
id (int 11)
username (varchar 35)
email (varchar 125)

++ Currently 1 testrow, 6.268 Bytes of data,
id is PRIMARY
username, email are UNIQUE

*************** *************** *************** *************** *************** *

The queries are as follows:

no joins at all: 0.59 secs
$get_news = mysql_query(" SELECT n.`id`, n.`published`, n.`title`,
n.`url`, n.`body`, n.`commentable`
FROM `ne_topics` n
WHERE n.`visible` = 1
AND n.`published` <= NOW()
ORDER BY n.`sticky` DESC, n.`published` DESC
LIMIT 12")or die(mysql_error ());

JOIN only username: 0.65 secs
$get_news = mysql_query(" SELECT n.`id`, n.`published`, n.`title`,
n.`url`, n.`body`, n.`commentable` ,
u.`screenname`, u.`email`
FROM `ne_topics` n, `gl_users` u
WHERE n.`visible` = 1
AND n.`published` <= NOW()
ORDER BY n.`sticky` DESC, n.`published` DESC
LIMIT 12")or die(mysql_error ());

all JOINs needed: 4.45 secs
$get_news = mysql_query(" SELECT n.`id`, n.`published`, n.`title`,
n.`url`, n.`body`, n.`commentable` ,
COUNT(f.`id`) AS 'fullbody',
COUNT(c.`id`) AS 'no_of_comments ',
u.`screenname`, u.`email`
FROM `ne_topics` n
LEFT JOIN `ne_fulltopic` f
ON (f.`id` = n.`id`)
LEFT JOIN `ne_comments` c
ON (c.`topic_id` = n.`id`)
LEFT JOIN `gl_users` u
ON (u.`id` = n.`author_id`)
WHERE n.`visible` = 1
AND n.`published` <= NOW()
GROUP BY n.`id`, u.`screenname`
ORDER BY n.`sticky` DESC, n.`published` DESC
LIMIT 12"

COUNT(f.`id`) AS 'fullbody' is to determine wheter or not a "read more"
link should appear.

Why oh why is this sooo slow? I really hope someone can help, since i'm
trying things for weeks now but just cannot figure it out ... :(

Frizzle.

Mar 13 '06 #1
11 1735
frizzle wrote:
Hi groupies

I'm building a news site, to wich a user can add new items into a mySQL
db.
It's still in testfase, but it's so extremely slow, i want to figure
out what i'm doing wrong, or what to change before it goes live ...
I know it's quite a long story, but i would be so happy if anyone could
help me out here ...
I've read on optimizing DB structure etc, but still cannot speed things
up ...

(Hope Google doesn't mess up the lines too much ... )

There are 4 relevant tables (yet) in the site:
1. ne_topics
2. ne_fulltopic
3. ne_comments
4. gl_users

*************** *************** *************** *************** *************** *

Table 1: ne_topics
id (int 11)
author_id (int 11) // user's id of whom created it.
creation (datetime) // datetime when item was created
publication (datetime) // datetime when item is (to be) published
title (varchar 35) // title of the item
url (varchar 35) // url of the item, anything a-z, 0-9, -
and _
body (text) // body text of item, including some
BBcodes
visible (tinyint 1) // is item visible or not ( 1 or 0 )
sticky (tinyint 1) // sticky or not ( 1 or 0 )

++ Currently 99.977 testrows, puplication dates random between 1-1-2000
and 31-12-2009, 60,1 MB of data,
id is PRIMARY
publication, url are UNIQUE
visible has INDEX

*************** *************** *************** *************** *************** *

Table 2: ne_fulltopic
id (int 11) // matches ne_topic.id, foreign keys not
available
fullbody (text) // contains an extended version of news

++ Currently 1 testrow, 2.904 Bytes of data,
id is PRIMARY

*************** *************** *************** *************** *************** *

Table 3: ne_comments
id (int 11)
topic_id (int 11) // to wich item does this comment belong
author_id (int 11) // user's id of whom created it.
comment (text) // comment of the user, including some
BBcodes

++ Currently 1 testrow, 4.124 Bytesof data,
id is PRIMARY
topic_id has INDEX

*************** *************** *************** *************** *************** *

Table 4: gl_users
id (int 11)
username (varchar 35)
email (varchar 125)

++ Currently 1 testrow, 6.268 Bytes of data,
id is PRIMARY
username, email are UNIQUE

*************** *************** *************** *************** *************** *

The queries are as follows:

no joins at all: 0.59 secs
$get_news = mysql_query(" SELECT n.`id`, n.`published`, n.`title`,
n.`url`, n.`body`, n.`commentable`
FROM `ne_topics` n
WHERE n.`visible` = 1
AND n.`published` <= NOW()
ORDER BY n.`sticky` DESC, n.`published` DESC
LIMIT 12")or die(mysql_error ());

JOIN only username: 0.65 secs
$get_news = mysql_query(" SELECT n.`id`, n.`published`, n.`title`,
n.`url`, n.`body`, n.`commentable` ,
u.`screenname`, u.`email`
FROM `ne_topics` n, `gl_users` u
WHERE n.`visible` = 1
AND n.`published` <= NOW()
ORDER BY n.`sticky` DESC, n.`published` DESC
LIMIT 12")or die(mysql_error ());

all JOINs needed: 4.45 secs
$get_news = mysql_query(" SELECT n.`id`, n.`published`, n.`title`,
n.`url`, n.`body`, n.`commentable` ,
COUNT(f.`id`) AS 'fullbody',
COUNT(c.`id`) AS 'no_of_comments ',
u.`screenname`, u.`email`
FROM `ne_topics` n
LEFT JOIN `ne_fulltopic` f
ON (f.`id` = n.`id`)
LEFT JOIN `ne_comments` c
ON (c.`topic_id` = n.`id`)
LEFT JOIN `gl_users` u
ON (u.`id` = n.`author_id`)
WHERE n.`visible` = 1
AND n.`published` <= NOW()
GROUP BY n.`id`, u.`screenname`
ORDER BY n.`sticky` DESC, n.`published` DESC
LIMIT 12"

COUNT(f.`id`) AS 'fullbody' is to determine wheter or not a "read more"
link should appear.

Why oh why is this sooo slow? I really hope someone can help, since i'm
trying things for weeks now but just cannot figure it out ... :(

Frizzle.


First of all, did you run EXPLAIN on your queries?

Also, is it even a MySQL problem? How's your hardware, for instance?
And what else is using system resources?

A lot of things can affect performance. Before you can improve the
performance you have to identify why it's running slow.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Mar 14 '06 #2

Jerry Stuckle wrote:
frizzle wrote:
Hi groupies

I'm building a news site, to wich a user can add new items into a mySQL
db.
It's still in testfase, but it's so extremely slow, i want to figure
out what i'm doing wrong, or what to change before it goes live ...
I know it's quite a long story, but i would be so happy if anyone could
help me out here ...
I've read on optimizing DB structure etc, but still cannot speed things
up ...

(Hope Google doesn't mess up the lines too much ... )

There are 4 relevant tables (yet) in the site:
1. ne_topics
2. ne_fulltopic
3. ne_comments
4. gl_users

*************** *************** *************** *************** *************** *

Table 1: ne_topics
id (int 11)
author_id (int 11) // user's id of whom created it.
creation (datetime) // datetime when item was created
publication (datetime) // datetime when item is (to be) published
title (varchar 35) // title of the item
url (varchar 35) // url of the item, anything a-z, 0-9, -
and _
body (text) // body text of item, including some
BBcodes
visible (tinyint 1) // is item visible or not ( 1 or 0 )
sticky (tinyint 1) // sticky or not ( 1 or 0 )

++ Currently 99.977 testrows, puplication dates random between 1-1-2000
and 31-12-2009, 60,1 MB of data,
id is PRIMARY
publication, url are UNIQUE
visible has INDEX

*************** *************** *************** *************** *************** *

Table 2: ne_fulltopic
id (int 11) // matches ne_topic.id, foreign keys not
available
fullbody (text) // contains an extended version of news

++ Currently 1 testrow, 2.904 Bytes of data,
id is PRIMARY

*************** *************** *************** *************** *************** *

Table 3: ne_comments
id (int 11)
topic_id (int 11) // to wich item does this comment belong
author_id (int 11) // user's id of whom created it.
comment (text) // comment of the user, including some
BBcodes

++ Currently 1 testrow, 4.124 Bytesof data,
id is PRIMARY
topic_id has INDEX

*************** *************** *************** *************** *************** *

Table 4: gl_users
id (int 11)
username (varchar 35)
email (varchar 125)

++ Currently 1 testrow, 6.268 Bytes of data,
id is PRIMARY
username, email are UNIQUE

*************** *************** *************** *************** *************** *

The queries are as follows:

no joins at all: 0.59 secs
$get_news = mysql_query(" SELECT n.`id`, n.`published`, n.`title`,
n.`url`, n.`body`, n.`commentable`
FROM `ne_topics` n
WHERE n.`visible` = 1
AND n.`published` <= NOW()
ORDER BY n.`sticky` DESC, n.`published` DESC
LIMIT 12")or die(mysql_error ());

JOIN only username: 0.65 secs
$get_news = mysql_query(" SELECT n.`id`, n.`published`, n.`title`,
n.`url`, n.`body`, n.`commentable` ,
u.`screenname`, u.`email`
FROM `ne_topics` n, `gl_users` u
WHERE n.`visible` = 1
AND n.`published` <= NOW()
ORDER BY n.`sticky` DESC, n.`published` DESC
LIMIT 12")or die(mysql_error ());

all JOINs needed: 4.45 secs
$get_news = mysql_query(" SELECT n.`id`, n.`published`, n.`title`,
n.`url`, n.`body`, n.`commentable` ,
COUNT(f.`id`) AS 'fullbody',
COUNT(c.`id`) AS 'no_of_comments ',
u.`screenname`, u.`email`
FROM `ne_topics` n
LEFT JOIN `ne_fulltopic` f
ON (f.`id` = n.`id`)
LEFT JOIN `ne_comments` c
ON (c.`topic_id` = n.`id`)
LEFT JOIN `gl_users` u
ON (u.`id` = n.`author_id`)
WHERE n.`visible` = 1
AND n.`published` <= NOW()
GROUP BY n.`id`, u.`screenname`
ORDER BY n.`sticky` DESC, n.`published` DESC
LIMIT 12"

COUNT(f.`id`) AS 'fullbody' is to determine wheter or not a "read more"
link should appear.

Why oh why is this sooo slow? I really hope someone can help, since i'm
trying things for weeks now but just cannot figure it out ... :(

Frizzle.


First of all, did you run EXPLAIN on your queries?

Also, is it even a MySQL problem? How's your hardware, for instance?
And what else is using system resources?

A lot of things can affect performance. Before you can improve the
performance you have to identify why it's running slow.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


Not to blow you off, but when i try to optimize things, i can go as far
as they're in my hands. (In this case only the PHP & MySQL)

EXPLAIN of the last query gave me the following:
table type possible_keys key key_len ref rows
Extra
n range published,visib le published 8 NULL 99977
where used; Using temporary; Using filesort
f index PRIMARY PRIMARY 3 NULL 1
Using index
c ALL topic_id NULL NULL NULL 1
u ALL PRIMARY,id NULL NULL NULL 1

MySQL Version: MySQL 3.23.58
PHP Version 4.3.10 (if this matters)
I'm not sure what else i could tell you.

Frizzle.

Mar 14 '06 #3
frizzle wrote:
Jerry Stuckle wrote:

First of all, did you run EXPLAIN on your queries?

Also, is it even a MySQL problem? How's your hardware, for instance?
And what else is using system resources?

A lot of things can affect performance. Before you can improve the
performance you have to identify why it's running slow.
--
============= =====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@att global.net
============= =====

Not to blow you off, but when i try to optimize things, i can go as far
as they're in my hands. (In this case only the PHP & MySQL)

EXPLAIN of the last query gave me the following:
table type possible_keys key key_len ref rows
Extra
n range published,visib le published 8 NULL 99977
where used; Using temporary; Using filesort
f index PRIMARY PRIMARY 3 NULL 1
Using index
c ALL topic_id NULL NULL NULL 1
u ALL PRIMARY,id NULL NULL NULL 1

MySQL Version: MySQL 3.23.58
PHP Version 4.3.10 (if this matters)
I'm not sure what else i could tell you.

Frizzle.


OK, well you didn't say you had run EXPLAIN on the queries, so I had no
way of knowing. A lot of people don't understand it.

A couple of things. First of all, it's not using an index on your
ne_comments and gl_users tables. I guess that would be normal since you
only have 1 row in each.

The other thing is it's doing a filesort on the temporary table. I
don't know if adding indicies to the sticky and published/visible (not
sure which one it is - your table shows `visible` but your query shows
`published` will help.

You could also check your sort buffer sizes. The defaults may be too
small for the amount of data you're sorting.

And you could run ANALYZE TABLE on your tables, but I don't think from
your EXPLAIN output it will help much if at all.

Additionally, I've found sometimes INNODB tables can improve performance.

And if you can upgrade to a more recent version of MySQL (3.2.23 is very
old), you'll probably get better performance. Optimization has been
improved since your version came out.

Hope this helps a little.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Mar 14 '06 #4

Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:

First of all, did you run EXPLAIN on your queries?

Also, is it even a MySQL problem? How's your hardware, for instance?
And what else is using system resources?

A lot of things can affect performance. Before you can improve the
performance you have to identify why it's running slow.
--
============= =====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@att global.net
============= =====

Not to blow you off, but when i try to optimize things, i can go as far
as they're in my hands. (In this case only the PHP & MySQL)

EXPLAIN of the last query gave me the following:
table type possible_keys key key_len ref rows
Extra
n range published,visib le published 8 NULL 99977
where used; Using temporary; Using filesort
f index PRIMARY PRIMARY 3 NULL 1
Using index
c ALL topic_id NULL NULL NULL 1
u ALL PRIMARY,id NULL NULL NULL 1

MySQL Version: MySQL 3.23.58
PHP Version 4.3.10 (if this matters)
I'm not sure what else i could tell you.

Frizzle.


OK, well you didn't say you had run EXPLAIN on the queries, so I had no
way of knowing. A lot of people don't understand it.

A couple of things. First of all, it's not using an index on your
ne_comments and gl_users tables. I guess that would be normal since you
only have 1 row in each.

The other thing is it's doing a filesort on the temporary table. I
don't know if adding indicies to the sticky and published/visible (not
sure which one it is - your table shows `visible` but your query shows
`published` will help.

You could also check your sort buffer sizes. The defaults may be too
small for the amount of data you're sorting.

And you could run ANALYZE TABLE on your tables, but I don't think from
your EXPLAIN output it will help much if at all.

Additionally, I've found sometimes INNODB tables can improve performance.

And if you can upgrade to a more recent version of MySQL (3.2.23 is very
old), you'll probably get better performance. Optimization has been
improved since your version came out.

Hope this helps a little.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


Hmm, so no real solution. Too bad ... :( I was really hoping to have
this problem solved.
Published has an index to it already, and InoDB isn't available on my
server ... :(

Thanks anyway.
I'll have to find another way for this system i guess, this is way too
slow. Do you maybe have any other structural tips or so to achieve the
same(ish) goal ?

Frizzle.

Mar 15 '06 #5

frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:

>
>First of all, did you run EXPLAIN on your queries?
>
>Also, is it even a MySQL problem? How's your hardware, for instance?
>And what else is using system resources?
>
>A lot of things can affect performance. Before you can improve the
>performance you have to identify why it's running slow.
>
>
>--
>============= =====
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>js*******@att global.net
>============= =====
Not to blow you off, but when i try to optimize things, i can go as far
as they're in my hands. (In this case only the PHP & MySQL)

EXPLAIN of the last query gave me the following:
table type possible_keys key key_len ref rows
Extra
n range published,visib le published 8 NULL 99977
where used; Using temporary; Using filesort
f index PRIMARY PRIMARY 3 NULL 1
Using index
c ALL topic_id NULL NULL NULL 1
u ALL PRIMARY,id NULL NULL NULL 1

MySQL Version: MySQL 3.23.58
PHP Version 4.3.10 (if this matters)
I'm not sure what else i could tell you.

Frizzle.


OK, well you didn't say you had run EXPLAIN on the queries, so I had no
way of knowing. A lot of people don't understand it.

A couple of things. First of all, it's not using an index on your
ne_comments and gl_users tables. I guess that would be normal since you
only have 1 row in each.

The other thing is it's doing a filesort on the temporary table. I
don't know if adding indicies to the sticky and published/visible (not
sure which one it is - your table shows `visible` but your query shows
`published` will help.

You could also check your sort buffer sizes. The defaults may be too
small for the amount of data you're sorting.

And you could run ANALYZE TABLE on your tables, but I don't think from
your EXPLAIN output it will help much if at all.

Additionally, I've found sometimes INNODB tables can improve performance.

And if you can upgrade to a more recent version of MySQL (3.2.23 is very
old), you'll probably get better performance. Optimization has been
improved since your version came out.

Hope this helps a little.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


Hmm, so no real solution. Too bad ... :( I was really hoping to have
this problem solved.
Published has an index to it already, and InoDB isn't available on my
server ... :(

Thanks anyway.
I'll have to find another way for this system i guess, this is way too
slow. Do you maybe have any other structural tips or so to achieve the
same(ish) goal ?

Frizzle.


Well, informed the host, and it appears i'm having mySQL upgraded this
week! :)
Do you expect things to speed up a lot (as far as you can say), or
should i hold my horses?

Frizzle.

Mar 15 '06 #6

frizzle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
> Jerry Stuckle wrote:
>
>>
>>First of all, did you run EXPLAIN on your queries?
>>
>>Also, is it even a MySQL problem? How's your hardware, for instance?
>>And what else is using system resources?
>>
>>A lot of things can affect performance. Before you can improve the
>>performance you have to identify why it's running slow.
>>
>>
>>--
>>============= =====
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>js*******@att global.net
>>============= =====
>
>
> Not to blow you off, but when i try to optimize things, i can go as far
> as they're in my hands. (In this case only the PHP & MySQL)
>
> EXPLAIN of the last query gave me the following:
> table type possible_keys key key_len ref rows
> Extra
> n range published,visib le published 8 NULL 99977
> where used; Using temporary; Using filesort
> f index PRIMARY PRIMARY 3 NULL 1
> Using index
> c ALL topic_id NULL NULL NULL 1
> u ALL PRIMARY,id NULL NULL NULL 1
>
>
>
> MySQL Version: MySQL 3.23.58
> PHP Version 4.3.10 (if this matters)
>
>
> I'm not sure what else i could tell you.
>
> Frizzle.
>

OK, well you didn't say you had run EXPLAIN on the queries, so I had no
way of knowing. A lot of people don't understand it.

A couple of things. First of all, it's not using an index on your
ne_comments and gl_users tables. I guess that would be normal since you
only have 1 row in each.

The other thing is it's doing a filesort on the temporary table. I
don't know if adding indicies to the sticky and published/visible (not
sure which one it is - your table shows `visible` but your query shows
`published` will help.

You could also check your sort buffer sizes. The defaults may be too
small for the amount of data you're sorting.

And you could run ANALYZE TABLE on your tables, but I don't think from
your EXPLAIN output it will help much if at all.

Additionally, I've found sometimes INNODB tables can improve performance.

And if you can upgrade to a more recent version of MySQL (3.2.23 is very
old), you'll probably get better performance. Optimization has been
improved since your version came out.

Hope this helps a little.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


Hmm, so no real solution. Too bad ... :( I was really hoping to have
this problem solved.
Published has an index to it already, and InoDB isn't available on my
server ... :(

Thanks anyway.
I'll have to find another way for this system i guess, this is way too
slow. Do you maybe have any other structural tips or so to achieve the
same(ish) goal ?

Frizzle.


Well, informed the host, and it appears i'm having mySQL upgraded this
week! :)
Do you expect things to speed up a lot (as far as you can say), or
should i hold my horses?

Frizzle.


Step by step it seems i'm getting closer to my goal!!!
I now have another appraoch, which takes the time from 5 secs to .5
(still quite slow, but acceptable) I first select the id's from the
right news articles,
and then, i perform the joins etc. on only those returned articles
using subqueries.

But, (of course there's a but) i get an error. I've read upon
subqueries, using 'IN' in subqueries, but it still doesn't make sense.
Separately both queries work, but together they don't.

The query is below, and the error looks like this:
You have an error in your SQL syntax near 'SELECT t.`id` FROM
`ne_topics` t WHERE t.`' at line 12

SELECT n.`id`, n.`published`, n.`title`, n.`url`, n.`body`,
COUNT(f.`id`) AS 'fullbody',
COUNT(c.`id`) AS 'no_of_comments ',
u.`screenname`, u.`email`
FROM `ne_topics` n
LEFT JOIN `ne_fulltopic` f
ON (f.`id` = n.`id`)
LEFT JOIN `ne_comments` c
ON (c.`topic_id` = n.`id`)
LEFT JOIN `gl_users` u
ON (u.`id` = n.`author_id`)
WHERE n.`id` IN( SELECT `id`
FROM `ne_topics`
WHERE `visible` = 1
AND `published` <= NOW()
ORDER BY `sticky` DESC, `published` DESC
LIMIT 12 )
GROUP BY n.`id`"

Why does this give me an error?

Frizzle.

Mar 15 '06 #7
frizzle said the following on 15/03/2006 16:28:
The query is below, and the error looks like this:
You have an error in your SQL syntax near 'SELECT t.`id` FROM
`ne_topics` t WHERE t.`' at line 12

SELECT n.`id`, n.`published`, n.`title`, n.`url`, n.`body`,
COUNT(f.`id`) AS 'fullbody',
COUNT(c.`id`) AS 'no_of_comments ',
u.`screenname`, u.`email`
FROM `ne_topics` n
LEFT JOIN `ne_fulltopic` f
ON (f.`id` = n.`id`)
LEFT JOIN `ne_comments` c
ON (c.`topic_id` = n.`id`)
LEFT JOIN `gl_users` u
ON (u.`id` = n.`author_id`)
WHERE n.`id` IN( SELECT `id`
FROM `ne_topics`
WHERE `visible` = 1
AND `published` <= NOW()
ORDER BY `sticky` DESC, `published` DESC
LIMIT 12 )
GROUP BY n.`id`"


Are you sure that's the error that corresponds to this query? Because
you don't have anything called "t" in your query, and nothing in your
query matches the syntax referred to in the error message...

BTW, it's not necessary to back-tick (`) every field name in the query,
and it makes it quite hard to read. Also, your aliases ("fullbody" and
"no_of_comments ") are quoted in single-quotes, which I is wrong, I think.
--
Oli
Mar 15 '06 #8

Oli Filth wrote:
frizzle said the following on 15/03/2006 16:28:
The query is below, and the error looks like this:
You have an error in your SQL syntax near 'SELECT t.`id` FROM
`ne_topics` t WHERE t.`' at line 12

SELECT n.`id`, n.`published`, n.`title`, n.`url`, n.`body`,
COUNT(f.`id`) AS 'fullbody',
COUNT(c.`id`) AS 'no_of_comments ',
u.`screenname`, u.`email`
FROM `ne_topics` n
LEFT JOIN `ne_fulltopic` f
ON (f.`id` = n.`id`)
LEFT JOIN `ne_comments` c
ON (c.`topic_id` = n.`id`)
LEFT JOIN `gl_users` u
ON (u.`id` = n.`author_id`)
WHERE n.`id` IN( SELECT `id`
FROM `ne_topics`
WHERE `visible` = 1
AND `published` <= NOW()
ORDER BY `sticky` DESC, `published` DESC
LIMIT 12 )
GROUP BY n.`id`"


Are you sure that's the error that corresponds to this query? Because
you don't have anything called "t" in your query, and nothing in your
query matches the syntax referred to in the error message...

BTW, it's not necessary to back-tick (`) every field name in the query,
and it makes it quite hard to read. Also, your aliases ("fullbody" and
"no_of_comments ") are quoted in single-quotes, which I is wrong, I think.
--
Oli


Sorry, i copy posted the wrong error. :$ It should be:
You have an error in your SQL syntax near 'SELECT `id` FROM `ne_topics`
WHERE `visibl' at line 12

Mar 15 '06 #9
frizzle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:

Jerry Stuckle wrote:
>First of all, did you run EXPLAIN on your queries?
>
>Also, is it even a MySQL problem? How's your hardware, for instance?
>And what else is using system resources?
>
>A lot of things can affect performance. Before you can improve the
>performanc e you have to identify why it's running slow.
>
>
>--
>========== ========
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>js*******@ attglobal.net
>========== ========
Not to blow you off, but when i try to optimize things, i can go as far
as they're in my hands. (In this case only the PHP & MySQL)

EXPLAIN of the last query gave me the following:
table type possible_keys key key_len ref rows
Extra
n range published,visib le published 8 NULL 99977
where used; Using temporary; Using filesort
f index PRIMARY PRIMARY 3 NULL 1
Using index
c ALL topic_id NULL NULL NULL 1
u ALL PRIMARY,id NULL NULL NULL 1

MySQL Version: MySQL 3.23.58
PHP Version 4.3.10 (if this matters)
I'm not sure what else i could tell you.

Frizzle.
OK, well you didn't say you had run EXPLAIN on the queries, so I had no
way of knowing. A lot of people don't understand it.

A couple of things. First of all, it's not using an index on your
ne_comment s and gl_users tables. I guess that would be normal since you
only have 1 row in each.

The other thing is it's doing a filesort on the temporary table. I
don't know if adding indicies to the sticky and published/visible (not
sure which one it is - your table shows `visible` but your query shows
`published ` will help.

You could also check your sort buffer sizes. The defaults may be too
small for the amount of data you're sorting.

And you could run ANALYZE TABLE on your tables, but I don't think from
your EXPLAIN output it will help much if at all.

Additionally , I've found sometimes INNODB tables can improve performance.

And if you can upgrade to a more recent version of MySQL (3.2.23 is very
old), you'll probably get better performance. Optimization has been
improved since your version came out.

Hope this helps a little.

--
============ ======
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@at tglobal.net
============ ======


Hmm, so no real solution. Too bad ... :( I was really hoping to have
this problem solved.
Published has an index to it already, and InoDB isn't available on my
server ... :(

Thanks anyway.
I'll have to find another way for this system i guess, this is way too
slow. Do you maybe have any other structural tips or so to achieve the
same(ish) goal ?

Frizzle.

Well, informed the host, and it appears i'm having mySQL upgraded this
week! :)
Do you expect things to speed up a lot (as far as you can say), or
should i hold my horses?

Frizzle.


It depends a lot on what they upgrade to. Hold your horses until you
see what happens.

Once you've got the new system up, run ANALYZE TABLE on all your tables
and try again. If it's still slow, see if they'll increase the sort
buffer sizes; the default is only 2M and you're probably returning a lot
more than that.

Another alternative if the problem is the sort buffer size is to just
get the basic information to select the records. Don't get the body and
URL, for instance, to cut down the size of the data being sorted. Then
as you fetch the rows, perform another MySQL query to get your text
data. If the problem is the sort buffer size, this might cut it down
enough to make the sort faster.

Plus - if you're not actually displaying all the returned data on one
page (what happens if you get 3000 rows returned?) you'll end up cutting
down additional overhead.

BTW - this really should be over in comp.databases. mysql, since it isn't
a PHP question.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Mar 15 '06 #10

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

Similar topics

5
2493
by: Mudge | last post by:
Hi, I am relatively new to PHP, but I don't care about that. I want to build a database driven Web site that is really a content management system that allows visitors to register and log in and write stories for the web site, and also allows visitors to vote on the articles. I'm thinking that maybe I should use a content management system in existence already because it might save time, then if i need to, i could just change the system...
12
3225
by: jonathan.beckett | last post by:
Hi All, For the past few months I have been working on an open source Apache/PHP/MySQL content management system - and have recently made it available for download. It's still very much a work in progress (current release version is 0.4.6), but you should get a very good idea of what it's about by visiting the site (which uses it, funnily enough), or downloading a copy of it and trying it out.
0
2323
by: jonathan.beckett | last post by:
Hi All, I have just made version 0.4.8 of the PluggedOut CMS Content Management System available for download - it's free, and covered by the GPL. It's still very much a work in progress (current release version is 0.4.8), but you should get a very good idea of what it's about by visiting the site (which uses it, funnily enough), or downloading a copy of it and trying it out.
8
7117
by: Mike | last post by:
Hi! Im working on some research for a asset management system. We will use python as our primary platform. As a opensource programmer the obvious question is; are there any opensource systems available? I found an article about ilm's system (story from python.org), sounds very interesting. Im looking for more information about similar systems (of course python based!), all feedback is welcome!
2
1837
by: Joe | last post by:
Hi, I have a newsletter subscribe page. A user enters email address and clicks Subscribe button. That email address is added to database. Say this is a career newsletter. Is it possible to create an intelligent system that will work such a way that every time a new job is added on the website, a newsletter is sent to all the email address that are currently in the database. I guess this is possible if one has a CMS (Content Management...
0
1636
by: roger23 | last post by:
I get this error C:\Program Files\MSBuild\Microsoft\WebDeployment\v8.0\Microsoft.WebDeployment.targets(526,9): error MSB6006: "aspnet_compiler.exe" exited with code 1. at the end of my build step of my web deployment project. it does not give me any error messages to debug. the only place where i can see some problem is this: Dependency "System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
6
1807
by: ARC | last post by:
I'm almost ready to build an upgrade routine for a commercial app that will need to import data from an existing Access 97 back-end database to an Access 2007 back-end blank database. Ideally, it would be nice to have the program detect, on first launch, whether the back end database is blank, and ask the user if they want to begin a new database (putting them into the blank one), or import data from the previous version (the access 97...
4
2125
by: Asaf Hayman | last post by:
Is anyone familiar or aware of a successful enterprise class project in Python to control and monitor a cluster of computers? As a part of a bigger project my company needs to build a cluster management system. The aim of the system is to control and synchronize applications. Namely, a central management will get events from the remote applications and from a user and will react with commands to the applications. Existing tools don’t...
2
4654
by: karthi84 | last post by:
Hi Experts, i have created a web application which has an option to edit the web config file from the web page. when i create an installer for this project using web setup project in VS2008 and install it, the codes are copied to the virtual directory under Inetpub. when i try to edit the web.config file it throws an exception access is denied to web.config file. but the same project works fine if i copy the file to some other location and...
0
8889
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, 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...
0
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9257
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 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...
0
9116
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6702
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 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...
0
6011
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();...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
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
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.