after updating my server php tp 5.3.3 the menu on joomla 1.5.6 doesn't work any more,
when I turned on the debug mode the below message appears
Profile Information
Application afterLoad: 0.005 seconds, 0.52 MB
Application afterInitialise: 0.877 seconds, 4.12 MB
Application afterRoute: 0.881 seconds, 4.45 MB
Application afterDispatch: 0.930 seconds, 6.21 MB
Application afterRender: 0.956 seconds, 6.64 MB
Memory Usage
7002564
10 queries logged
1. DELETE
FROM jos_session
WHERE ( time < '1329434797' )
2. SELECT *
FROM jos_session
WHERE session_id = 'vrklkcuiohl12g3la0lm4gp5v3'
3. UPDATE `jos_session`
SET `time`='1329435697',`userid`='0',`usertype`='',`username`='',`gid`='0',`guest`='1',`client_id`='0',`data`='__default|a:7:{s:15:\"session.counter\";i:3;s:19:\"session.timer.start\";i:1329434953;s:18:\"session.timer.last\";i:1329435238;s:17:\"session.timer.now\";i:1329435250;s:22:\"session.client.browser\";s:69:\"Mozilla/5.0 (Windows NT 6.1; rv:10.0.1) Gecko/20100101 Firefox/10.0.1\";s:8:\"registry\";O:9:\"JRegistry\":3:{s:17:\"_defaultNameSpace\";s:7:\"session\";s:9:\"_registry\";a:1:{s:7:\"session\";a:1:{s:4:\"data\";O:8:\"stdClass\":0:{}}}s:7:\"_errors\";a:0:{}}s:4:\"user\";O:5:\"JUser\":19:{s:2:\"id\";i:0;s:4:\"name\";N;s:8:\"username\";N;s:5:\"email\";N;s:8:\"password\";N;s:14:\"password_clear\";s:0:\"\";s:8:\"usertype\";N;s:5:\"block\";N;s:9:\"sendEmail\";i:0;s:3:\"gid\";i:0;s:12:\"registerDate\";N;s:13:\"lastvisitDate\";N;s:10:\"activation\";N;s:6:\"params\";N;s:3:\"aid\";i:0;s:5:\"guest\";i:1;s:7:\"_params\";O:10:\"JParameter\":7:{s:4:\"_raw\";s:0:\"\";s:4:\"_xml\";N;s:9:\"_elements\";a:0:{}s:12:\"_elementPath\";a:1:{i:0;s:63:\"/usr/www/users/mysite/libraries/joomla/html/parameter/element\";}s:17:\"_defaultNameSpace\";s:8:\"_default\";s:9:\"_registry\";a:1:{s:8:\"_default\";a:1:{s:4:\"data\";O:8:\"stdClass\":0:{}}}s:7:\"_errors\";a:0:{}}s:9:\"_errorMsg\";N;s:7:\"_errors\";a:0:{}}}'
WHERE session_id='vrklkcuiohl12g3la0lm4gp5v3'
4. SELECT *
FROM jos_components
WHERE parent = 0
5. SELECT folder AS type, element AS name, params
FROM jos_plugins
WHERE published >= 1
AND access <= 0
ORDER BY ordering
6. SELECT m.*, c.`option` AS component
FROM jos_menu AS m
LEFT JOIN jos_components AS c
ON m.componentid = c.id
WHERE m.published = 1
ORDER BY m.sublevel, m.parent, m.ordering
7. SELECT template
FROM jos_templates_menu
WHERE client_id = 0
AND (menuid = 0 OR menuid = 1)
ORDER BY menuid DESC
LIMIT 0, 1
8. SELECT a.id, a.title, a.title_alias, a.introtext, a.fulltext, a.sectionid, a.state, a.catid, a.created, a.created_by, a.created_by_alias, a.modified, a.modified_by, a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, a.images, a.attribs, a.urls, a.metakey, a.metadesc, a.access, CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(':', a.id, a.alias) ELSE a.id END AS slug, CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END AS catslug, CHAR_LENGTH( a.`fulltext` ) AS readmore, u.name AS author, u.usertype, g.name AS groups, cc.title AS category, s.title AS section, s.ordering AS s_ordering, cc.ordering AS cc_ordering, a.ordering AS a_ordering, f.ordering AS f_ordering
FROM jos_content AS a
INNER JOIN jos_content_frontpage AS f
ON f.content_id = a.id
LEFT JOIN jos_categories AS cc
ON cc.id = a.catid
LEFT JOIN jos_sections AS s
ON s.id = a.sectionid
LEFT JOIN jos_users AS u
ON u.id = a.created_by
LEFT JOIN jos_groups AS g
ON a.access = g.id
WHERE 1
AND a.access <= 0
AND a.state = 1
AND (( cc.published = 1
AND s.published = 1 ) OR ( a.catid = 0
AND a.sectionid = 0 ) )
AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2012-02-16 23:41:37' )
AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2012-02-16 23:41:37' )
ORDER BY f.ordering
LIMIT 0, 9
9. SELECT a.id, a.title, a.title_alias, a.introtext, a.fulltext, a.sectionid, a.state, a.catid, a.created, a.created_by, a.created_by_alias, a.modified, a.modified_by, a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, a.images, a.attribs, a.urls, a.metakey, a.metadesc, a.access, CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(':', a.id, a.alias) ELSE a.id END AS slug, CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END AS catslug, CHAR_LENGTH( a.`fulltext` ) AS readmore, u.name AS author, u.usertype, g.name AS groups, cc.title AS category, s.title AS section, s.ordering AS s_ordering, cc.ordering AS cc_ordering, a.ordering AS a_ordering, f.ordering AS f_ordering
FROM jos_content AS a
INNER JOIN jos_content_frontpage AS f
ON f.content_id = a.id
LEFT JOIN jos_categories AS cc
ON cc.id = a.catid
LEFT JOIN jos_sections AS s
ON s.id = a.sectionid
LEFT JOIN jos_users AS u
ON u.id = a.created_by
LEFT JOIN jos_groups AS g
ON a.access = g.id
WHERE 1
AND a.access <= 0
AND a.state = 1
AND (( cc.published = 1
AND s.published = 1 ) OR ( a.catid = 0
AND a.sectionid = 0 ) )
AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2012-02-16 23:41:37' )
AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2012-02-16 23:41:37' )
ORDER BY f.ordering
10. SELECT id, title, module, position, content, showtitle, control, params
FROM jos_modules AS m
LEFT JOIN jos_modules_menu AS mm
ON mm.moduleid = m.id
WHERE m.published = 1
AND m.access <= 0
AND m.client_id = 0
AND ( mm.menuid = 1 OR mm.menuid = 0 )
ORDER BY position, ordering
0 legacy queries logged
Language Files Loaded
• /usr/www/users/mysite/language/en-GB/en-GB.ini 1
• /usr/www/users/mysite/language/en-GB/en-GB.plg_system_debug.ini 1
• /usr/www/users/mysite/language/en-GB/en-GB.com_content.ini 1
• /usr/www/users/mysite/language/en-GB/en-GB.tpl_js_weblogic_brown.ini
• /usr/www/users/mysite/language/en-GB/en-GB.mod_breadcrumbs.ini 1
• /usr/www/users/mysite/language/en-GB/en-GB.mod_search.ini 1
• /usr/www/users/mysite/language/en-GB/en-GB.mod_mainmenu.ini 1
Untranslated Strings Diagnostic
None
Untranslated Strings Designer
None
PHP error as below
"17 Feb 2012 12:50:36","/usr/www/users/mysite/libraries/joomla/language/language.php: 336","(Warning) file_get_contents(/usr/www/users/mysite/language/en-GB/en-GB.tpl_js_weblogic_brown.ini): failed to open stream: No such file or directory"
"17 Feb 2012 12:50:36","/usr/www/users/mysite/libraries/joomla/language/language.php: 336","(Warning) file_get_contents(/usr/www/users/mysite/language/en-GB/en-GB.tpl_js_weblogic_brown.ini): failed to open stream: No such file or directory"
"17 Feb 2012 12:50:49","/usr/www/users/mysite/libraries/joomla/language/language.php: 336","(Warning) file_get_contents(/usr/www/users/mysite/language/en-GB/en-GB.tpl_js_weblogic_brown.ini): failed to open stream: No such file or directory"
"17 Feb 2012 12:50:49","/usr/www/users/mysite/libraries/joomla/language/language.php: 336","(Warning) file_get_contents(/usr/www/users/mysite/language/en-GB/en-GB.tpl_js_weblogic_brown.ini): failed to open stream: No such file or directory"
"17 Feb 2012 13:19:34","/usr/www/users/mysite/plugins/content/plugin_googlemap2.php: 432","(Deprecated) Assigning the return value of new by reference is deprecated"
"17 Feb 2012 13:30:52","/usr/www/users/mysite/plugins/content/plugin_googlemap2.php: 432","(Deprecated) Assigning the return value of new by reference is deprecated"
"17 Feb 2012 13:31:00","/usr/www/users/mysite/plugins/content/plugin_googlemap2.php: 432","(Deprecated) Assigning the return value of new by reference is deprecated"
Any body can help to solve this and make my menu work again?
Reinstall the template and the menu shall appear again.
And what about upgrading your Joomla to the latest version?
What are the menus which are not appearing?
front-end menus or back-end menus?
Also, have you tried to reinstall the admin menu too?
This problem is common when updating Joomla, and usually because the template menus are hardcoded.
-- Edit
Just noticed the error messages you posted below.
"17 Feb 2012 12:50:36","/usr/www/users/mysite/libraries/joomla/language/language.php: 336","(Warning) file_get_contents(/usr/www/users/mysite/language/en-GB/en-GB.tpl_js_weblogic_brown.ini): failed to open stream: No such file or directory"
This one indicates you have a missing language file (file name: en-GB.tpl_js_weblogic_brown.ini), related to the template (weblogic brown style). maybe this is the reason for disappeared menu.
Related
$sql = "SELECT CC.*, CS.name as status_name, OS.name AS order_status_name, OS.id as order_status_id, O.payment_way, O.ship_country,O.bank_id,O.payment_text, O.reference_no, O.date_comp, O.rate as rate, O.currency as currency, IF(O.payment_way=4,'TEST',B.name) as bank_name, ICR.cancel_id, ICR.result, ICR.response
FROM cancels CC
INNER JOIN orders O ON O.id = CC.order_id
LEFT JOIN order_products OP ON OP.parent=O.id
LEFT JOIN product_variants PV ON PV.id=OP.product_variant_id
LEFT JOIN products P ON P.id=PV.product_id
LEFT JOIN banks B ON B.id=O.bank_id
LEFT JOIN order_status OS ON OS.id = O.status
LEFT JOIN mp_external_order AS meo ON meo.mdns_order_id = O.id
LEFT JOIN cancel_status AS CS ON CS.cname = CC.status
LEFT JOIN (SELECT IC.cancel_id, IC.result, IC.response, MAX(IC.id) AS cancels FROM internal_cancel_requests IC GROUP BY IC.cancel_id, IC.result, IC.response) AS ICR ON CC.id = ICR.cancel_id
WHERE CC.date_add BETWEEN '2021-03-10 00:00:00' AND '2021-08-10 23:59:59' AND CC.deleted = 0 AND CC.total <> 0 AND meo.id IS NULL AND CC.status NOT IN ('REF', 'M_REF') GROUP BY CC.id ORDER BY C.date_add ASC";
$query = selectQuery($sql);
in the code block above
LEFT JOIN (SELECT IC.cancel_id, IC.result, IC.response, MAX(IC.id) AS cancels FROM internal_cancel_requests IC GROUP BY IC.cancel_id, IC.result, IC.response) AS ICR ON CC.id = ICR.cancel_id
line causing slownes.
Without changing the date range and adding limits for uploaded big data. How should I change this line of code to improve performance.
internal_cancel_requests table
id
cancel_id
response
result
1
1250
xxxxx
1
2
1250
xyxyxy
0
3
1251
xx
0
in the above table For record number 1250 cancel_id, record number 2 must be brought
My website is experiencing very slow queries like the one below. It is Joomla 2.5.
# Query_time: 19.797091 Lock_time: 0.000561 Rows_sent: 12 Rows_examined: 4127
SET timestamp=1385467501;
SELECT a.fulltext, a.id, a.title, a.alias, a.title_alias, a.introtext, a.state, a.catid, a.created, a.created_by, a.created_by_alias,a.images, a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, a.hits, a.featured, LENGTH(a.fulltext) AS readmore,a.fulltext, a.id, a.title, a.alias, a.title_alias, a.introtext, a.state, a.catid, a.created, a.created_by, a.created_by_alias,a.images, a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, a.hits, a.featured, LENGTH(a.fulltext) AS readmore,c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias,CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author,ua.email AS author_email,contact.id as contactid,parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias,ROUND(v.rating_sum / v.rating_count, 0) AS rating, v.rating_count as rating_count,c.published, CASE WHEN badcats.id is null THEN c.published ELSE 0 END AS parents_published
FROM j25_content AS a
LEFT JOIN j25_content_frontpage AS fp ON fp.content_id = a.id
LEFT JOIN j25_categories AS c ON c.id = a.catid
LEFT JOIN j25_users AS ua ON ua.id = a.created_by
LEFT JOIN j25_users AS uam ON uam.id = a.modified_by
LEFT JOIN (
SELECT contact.user_id, MAX(contact.id) AS id, contact.language
FROM j25_contact_details AS contact
WHERE contact.published = 1
GROUP BY contact.user_id, contact.language) AS contact ON contact.user_id = a.created_by
LEFT JOIN j25_categories as parent ON parent.id = c.parent_id
LEFT JOIN j25_content_rating AS v ON a.id = v.content_id
LEFT OUTER JOIN (SELECT cat.id as id FROM j25_categories AS cat JOIN j25_categories AS parent ON cat.lft BETWEEN parent.lft AND parent.rgt WHERE parent.extension = 'com_content' AND parent.published != 1 GROUP BY cat.id ) AS badcats ON badcats.id = c.id
WHERE a.access IN (1,1) AND c.access IN (1,1) AND CASE WHEN badcats.id is null THEN a.state ELSE 0 END = 1 AND a.featured = 0 AND a.catid IN (181,89,173,174,49,128,124,175,129,133,121,176,135,180,177,178,179,90) AND (a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2013-11-26 12:04:24') AND (a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2013-11-26 12:04:24')
GROUP BY a.id, a.title, a.alias, a.title_alias, a.introtext, a.checked_out, a.checked_out_time, a.catid, a.created, a.created_by, a.created_by_alias, a.created, a.modified, a.modified_by, uam.name, a.publish_up, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, a.hits, a.xreference, a.featured, a.fulltext, a.state, a.publish_down, badcats.id, c.title, c.path, c.access, c.alias, uam.id, ua.name, ua.email, contact.id, parent.title, parent.id, parent.path, parent.alias, v.rating_sum, v.rating_count, c.published, c.lft, a.ordering, parent.lft, fp.ordering, c.id, a.images, a.urls
ORDER BY a.created DESC LIMIT 0, 12;
What can I do to speed it up? Would indexing some of these tables help?
Thank you.
Absolutely indexes help in queries. And each of what I consider your secondary lookup reference tables (categories, users, content rating, etc) should have an index at a MINIMUM on what your join condition is between the tables.
table index on
j25_content ( access, featured, catid, publish_up, publish_down, state, id, created_by, modified_by )
j25_content_frontpage ( content_id )
j25_categories ( id, parent_id )
ANOTHER index...
j25_categories ( extension, published, lft, rgt, id )
j25_users ( id )
j25_contact_details ( published, user_id, language, id )
j25_content_rating ( content_id )
I've set these indexes up to be "covering" indexes... meaning they should help the optimization of the query by having all the fields as part of the index so it does not have to go to the raw data pages to see if all the pieces qualify to return a record
TRY that first...
NEXT thing I would try is MySQL has a special keyword "STRAIGHT_JOIN" which tells the
engine to run the query in the order you have stated. You seem to have a good basis
of the tables as the primary and your lookup as secondary. The engine might be trying
to think for you and use one of the smaller tables to run the query.
select STRAIGHT_JOIN (rest of your query exactly as it is)
Before I go any further, let me just say, I've already done everything that's recommended when you google "slow joomla" or "optimize joomla". That is, my site is GZipped, all of my css and js are optimized and minified, I'm not running any unnecessary components, plugins, or modules (hardly any, in fact), my images are optimized, caching is turned on (both page and Progressive) and I'm on supah-fast cloud hosting from Rackspace, with my SQL Database on a separate Rackspace server.
All of that, and I'm still getting load times upwards of 10-12 seconds, sometimes as much as 14-15.
From Joomla debug:
Application 0.000 seconds (+0.000); 0.75 MB (+0.755) - afterLoad
Application 0.027 seconds (+0.027); 2.25 MB (+1.491) - afterInitialise
Application 0.040 seconds (+0.013); 3.26 MB (+1.010) - afterRoute
Application 11.986 seconds (+11.947); 5.09 MB (+1.833) - afterDispatch
Application 12.000 seconds (+0.014); 5.63 MB (+0.539) - beforeRenderModule mod_chronoforms (Tip Line)
Application 12.006 seconds (+0.005); 5.85 MB (+0.225) - afterRenderModule mod_chronoforms (Tip Line)
Application 12.008 seconds (+0.002); 5.86 MB (+0.006) - beforeRenderModule mod_custom_advanced (Sponsors)
Application 12.009 seconds (+0.002); 5.88 MB (+0.019) - afterRenderModule mod_custom_advanced (Sponsors)
Application 12.010 seconds (+0.001); 5.87 MB (-0.006) - beforeRenderModule mod_flexi_customcode (Popular Now)
Application 12.012 seconds (+0.002); 5.89 MB (+0.018) - afterRenderModule mod_flexi_customcode (Popular Now)
Application 12.012 seconds (+0.001); 5.84 MB (-0.046) - beforeRenderModule mod_articles_category (Featured Articles)
Application 12.033 seconds (+0.021); 5.97 MB (+0.127) - afterRenderModule mod_articles_category (Featured Articles)
Application 12.033 seconds (+0.000); 5.96 MB (-0.014) - beforeRenderModule mod_search (Search)
Application 12.036 seconds (+0.002); 5.98 MB (+0.022) - afterRenderModule mod_search (Search)
Application 12.036 seconds (+0.001); 5.93 MB (-0.050) - beforeRenderModule mod_acymailing (AcyMailing Module)
Application 12.044 seconds (+0.007); 6.44 MB (+0.507) - afterRenderModule mod_acymailing (AcyMailing Module)
Application 12.157 seconds (+0.114); 6.72 MB (+0.289) - afterRender
the (+11.947) for afterDispatch is what tipped me off that it was probably an issue with the MySQL queries, so I started running some of the long (long, LONG) ones through PHPMyAdmin.
I found that queries such as these (the first of which loads 8 articles for the category-blog view -- as far as I understand, the second does the same search, minus the LIMIT, to allow for pagination) take over 2 or 3 second EACH to complete and there are 40-some-odd queries (though the vast majority are nowhere near as unwieldy) every time a page loads:
SELECT a.id, a.title, a.alias, a.introtext, a.checked_out, a.checked_out_time, a.catid, a.created, a.created_by, a.created_by_alias,
CASE WHEN a.modified = '0000-00-00 00:00:00' THEN a.created ELSE a.modified END as modified, a.modified_by, uam.name as modified_by_name,
CASE WHEN a.publish_up = '0000-00-00 00:00:00' THEN a.created ELSE a.publish_up END as publish_up,a.publish_down, a.images, a.urls, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, a.hits, a.xreference, a.featured, LENGTH(a.fulltext) AS readmore,
CASE WHEN badcats.id is not null THEN 0 ELSE a.state END AS state,c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias,
CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author,ua.email AS author_email,contact.id as contactid,parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias,ROUND(v.rating_sum / v.rating_count, 0) AS rating, v.rating_count as rating_count,c.published,
CASE WHEN badcats.id is null THEN c.published ELSE 0 END AS parents_published
FROM mydatabase_content AS a
LEFT JOIN mydatabase_content_frontpage AS fp
ON fp.content_id = a.id
LEFT JOIN mydatabase_categories AS c
ON c.id = a.catid
LEFT JOIN mydatabase_users AS ua
ON ua.id = a.created_by
LEFT JOIN mydatabase_users AS uam
ON uam.id = a.modified_by
LEFT JOIN ( SELECT contact.user_id, MAX(contact.id) AS id, contact.language
FROM mydatabase_contact_details AS contact
WHERE contact.published = 1
GROUP BY contact.user_id, contact.language) AS contact
ON contact.user_id = a.created_by
LEFT JOIN mydatabase_categories as parent
ON parent.id = c.parent_id
LEFT JOIN mydatabase_content_rating AS v
ON a.id = v.content_id
LEFT
OUTER JOIN (SELECT cat.id as id
FROM mydatabase_categories AS cat JOIN mydatabase_categories AS parent
ON cat.lft BETWEEN parent.lft
AND parent.rgt
WHERE parent.extension = 'com_content'
AND parent.published != 1
GROUP BY cat.id ) AS badcats
ON badcats.id = c.id
WHERE a.access IN (1,1,5)
AND c.access IN (1,1,5)
AND
CASE WHEN badcats.id is null THEN a.state ELSE 0 END = 1
AND (a.catid = 164 OR a.catid IN ( SELECT sub.id
FROM mydatabase_categories as sub
INNER JOIN mydatabase_categories as this
ON sub.lft > this.lft
AND sub.rgt < this.rgt
WHERE this.id = 164))
AND (a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2013-08-07 07:00:01')
AND (a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2013-08-07 07:00:01')
GROUP BY a.id, a.title, a.alias, a.introtext, a.checked_out, a.checked_out_time, a.catid, a.created, a.created_by, a.created_by_alias, a.created, a.modified, a.modified_by, uam.name, a.publish_up, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, a.hits, a.xreference, a.featured, a.fulltext, a.state, a.publish_down, badcats.id, c.title, c.path, c.access, c.alias, uam.id, ua.name, ua.email, contact.id, parent.title, parent.id, parent.path, parent.alias, v.rating_sum, v.rating_count, c.published, c.lft, a.ordering, parent.lft, fp.ordering, c.id, a.images, a.urls
ORDER BY
CASE WHEN a.publish_up = '0000-00-00 00:00:00' THEN a.created ELSE a.publish_up END DESC , a.created
LIMIT 0, 7
---
SELECT a.id, a.title, a.alias, a.introtext, a.checked_out, a.checked_out_time, a.catid, a.created, a.created_by, a.created_by_alias,
CASE WHEN a.modified = '0000-00-00 00:00:00' THEN a.created ELSE a.modified END as modified, a.modified_by, uam.name as modified_by_name,
CASE WHEN a.publish_up = '0000-00-00 00:00:00' THEN a.created ELSE a.publish_up END as publish_up,a.publish_down, a.images, a.urls, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, a.hits, a.xreference, a.featured, LENGTH(a.fulltext) AS readmore,
CASE WHEN badcats.id is not null THEN 0 ELSE a.state END AS state,c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias,
CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author,ua.email AS author_email,contact.id as contactid,parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias,ROUND(v.rating_sum / v.rating_count, 0) AS rating, v.rating_count as rating_count,c.published,
CASE WHEN badcats.id is null THEN c.published ELSE 0 END AS parents_published
FROM mydatabase_content AS a
LEFT JOIN mydatabase_content_frontpage AS fp
ON fp.content_id = a.id
LEFT JOIN mydatabase_categories AS c
ON c.id = a.catid
LEFT JOIN mydatabase_users AS ua
ON ua.id = a.created_by
LEFT JOIN mydatabase_users AS uam
ON uam.id = a.modified_by
LEFT JOIN ( SELECT contact.user_id, MAX(contact.id) AS id, contact.language
FROM mydatabase_contact_details AS contact
WHERE contact.published = 1
GROUP BY contact.user_id, contact.language) AS contact
ON contact.user_id = a.created_by
LEFT JOIN mydatabase_categories as parent
ON parent.id = c.parent_id
LEFT JOIN mydatabase_content_rating AS v
ON a.id = v.content_id
LEFT
OUTER JOIN (SELECT cat.id as id
FROM mydatabase_categories AS cat JOIN mydatabase_categories AS parent
ON cat.lft BETWEEN parent.lft
AND parent.rgt
WHERE parent.extension = 'com_content'
AND parent.published != 1
GROUP BY cat.id ) AS badcats
ON badcats.id = c.id
WHERE a.access IN (1,1,5)
AND c.access IN (1,1,5)
AND
CASE WHEN badcats.id is null THEN a.state ELSE 0 END = 1
AND (a.catid = 164 OR a.catid IN ( SELECT sub.id
FROM mydatabase_categories as sub
INNER JOIN mydatabase_categories as this
ON sub.lft > this.lft
AND sub.rgt < this.rgt
WHERE this.id = 164))
AND (a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2013-08-07 07:00:01')
AND (a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2013-08-07 07:00:01')
GROUP BY a.id, a.title, a.alias, a.introtext, a.checked_out, a.checked_out_time, a.catid, a.created, a.created_by, a.created_by_alias, a.created, a.modified, a.modified_by, uam.name, a.publish_up, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, a.hits, a.xreference, a.featured, a.fulltext, a.state, a.publish_down, badcats.id, c.title, c.path, c.access, c.alias, uam.id, ua.name, ua.email, contact.id, parent.title, parent.id, parent.path, parent.alias, v.rating_sum, v.rating_count, c.published, c.lft, a.ordering, parent.lft, fp.ordering, c.id, a.images, a.urls
ORDER BY
CASE WHEN a.publish_up = '0000-00-00 00:00:00' THEN a.created ELSE a.publish_up END DESC , a.created
EDIT
Here's the EXPLAIN for the first query:
And for the second:
My _content table is a little over 14,000 rows, which I know isn't really all that much in the grand scheme of things.
/EDIT
Has anyone found a good way to optimize this? I'm not opposed to hacking the core (I know they say not to, but what's the point of an open source project if you can't get in and fiddle with it?) if that's what it takes.
EDIT 2 - SOLVED (sort of).
So, I found this guy who seems to be going down the right path, so I said to hell with it, and tried it.
In components/com_content/models/articles.php, I replaced line 431
$query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')')
->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')');
with
$query->where('(a.publish_up >= DATE_SUB(NOW(), INTERVAL 1 YEAR))');
I know this won't work for everyone, as it probably breaks pagination, but it seems to be working for me so far (my template uses a js infinite scroll solution instead of pagination). I figure if anyone is looking for an article over a year old, they can use the Search function.
Those two queries now each take less that .04 seconds to complete, and the afterDispatch time from Joomla Debug is down to 1.469 seconds -- not optimal, but a number I can live with and continue to whittle down.
I know this solution is pretty hacky, and probably won't work for anyone else, so I'd love to hear more ideas about improving/optimizing the Joomla core and the Joomla stock queries.
Thanks SO!
/EDIT 2
As I have posted here already: JOOMLA site too slow
I uncommented the
bind-address="127.0.0.1"
setting in the MySQL configuration file (my.ini).
This brought an increase of execution speed to my local Joomla installation on Windows 8.1.
There is an issue with the join on the contact table and the resulting group_by.
This is fixed in master with https://github.com/joomla/joomla-cms/pull/1542 and I think it should already be included in the current release.
Which version of Joomla are you using?
i had a problem on windwos hosting php+mysql. set host to ip address.
host 127.0.0.1
I am making a dating app similar to tindler, where users can like or dislike each other. If two users both like each other, they should be able to chat with each other. I have come up with the following query to handle pulling a list of users you can chat/have chats with already - the problem i'm having is i only want to pull the most recent chat message, solely to display a little blurb before you click into the chat itself. My query works, but it returns the oldest (lowest ID) chat record, instead of the newest. Order by does not seem to have an impact on returning the correct result.
$data = $this->db->select('users.id,display_name,city,state,gender,users_pictures.picture,users_chats.message')
->join('users_pictures','users_pictures.user_id=users.id')
->join('users_chats','users_chats.user_id=users.id OR users_chats.foreign_user_id=users.id','left outer')
->where('EXISTS (SELECT 1 FROM users_likes_dislikes ld WHERE (ld.foreign_user_id = '.$this->user_id.' AND ld.user_id=users.id AND ld.event_type=1) OR (SELECT 1 FROM users_likes_dislikes ld WHERE ld.foreign_user_id = users.id AND ld.user_id='.$this->user_id.' AND ld.event_type=1))', '', FALSE)
->where('NOT EXISTS (SELECT 1 FROM users_blocks ub WHERE (ub.foreign_user_id = users.id AND ub.user_id='.$this->user_id.') OR (SELECT 1 FROM users_blocks ub WHERE ub.foreign_user_id = '.$this->user_id.' AND ub.user_id=users.id))', '', FALSE)
->where('((users_chats.user_id='.$this->user_id.' OR users_chats.foreign_user_id='.$this->user_id.') OR (users_chats.user_id is NULL AND users_chats.foreign_user_id is NULL))')
->order_by('users_chats.id','DESC')
->group_by('users.id')
->get('users')
->result_array();
Here is the current mysql table for users_chats:
id user_id foreign_user_id message created
1 1 4 test 2013-05-22 15:42:44
2 1 4 test2 2013-05-22 15:44:38
I assumed the order_by would ensure that the test2 message is what displayed.
Here is sample output:
Array ( [0] => Array ( [id] => 4 [display_name] => testinguser [city] => west hills [state] => ca [gender] => 2 [picture] => testasdfasdf.jpg [message] => test ) )
Any help is much appreciated :)
edit - the query itself (without group by, this works but i need it to group to the user.id so that i don't have multiple entries for the same user in the array):
SELECT
`users`.`id`,
`display_name`,
`city`,
`state`,
`gender`,
`users_pictures`.`picture`,
`users_chats`.`message`
FROM (`users`)
JOIN `users_pictures`
ON `users_pictures`.`user_id` = `users`.`id`
JOIN `users_chats`
ON `users_chats`.`user_id` = `users`.`id`
OR users_chats.foreign_user_id = users.id
WHERE EXISTS(SELECT
1
FROM users_likes_dislikes ld
WHERE (ld.foreign_user_id = 1
AND ld.user_id = users.id
AND ld.event_type = 1)
OR (SELECT
1
FROM users_likes_dislikes ld
WHERE ld.foreign_user_id = users.id
AND ld.user_id = 1
AND ld.event_type = 1))
AND NOT EXISTS(SELECT
1
FROM users_blocks ub
WHERE (ub.foreign_user_id = users.id
AND ub.user_id = 1)
OR (SELECT
1
FROM users_blocks ub
WHERE ub.foreign_user_id = 1
AND ub.user_id = users.id))
AND ((users_chats.user_id = 1
OR users_chats.foreign_user_id = 1)
OR (users_chats.user_id is NULL
AND users_chats.foreign_user_id is NULL))
ORDER BY `users_chats`.`created` DESC
Your group by clause could be the culprit here. I believe that the grouping operation happens first, leaving you with your first result.
Rather than selecting all these rows (when there's tons it'll take longer), you should specify how many you want - it looks to me like that isn't too far out of the picture here, anyways. Specify how many you want, get rid of the group by clause, and you should order by date since you HAVE a date column.
Does that help?
I'm not sure how to do it with your db Abstraction, but the query you want is
SELECT
`users`.`id`,
`display_name`,
`city`,
`state`,
`gender`,
`users_pictures`.`picture`,
chats1.`message`
FROM (`users`)
JOIN `users_pictures`
ON `users_pictures`.`user_id` = `users`.`id`
JOIN `users_chats` AS chats1
ON (chats1.`user_id` = `users`.`id`
OR chats1.foreign_user_id = users.id)
Here comes the important part
AND NOT EXISTS(
SELECT *
FROM users_chats AS chats2
WHERE ((chats2.user_id = chats1.user_id AND chats2.foreign_user_id = chats1.foreign_user_id)
OR (chats2.user_id = chats1.foreign_user_id AND chats1.user_id = chats2.foreign_user_id))
AND chats2.created_date > chats1.created_date --which I assume is a time stamp
)
It's not pretty, I know.
WHERE EXISTS(SELECT 1
FROM users_likes_dislikes ld
WHERE (ld.foreign_user_id = 1
AND ld.user_id = users.id
AND ld.event_type = 1)
OR (SELECT 1
FROM users_likes_dislikes ld
WHERE ld.foreign_user_id = users.id
AND ld.user_id = 1
AND ld.event_type = 1)
)
AND NOT EXISTS(SELECT 1
FROM users_blocks ub
WHERE (ub.foreign_user_id = users.id
AND ub.user_id = 1)
OR (SELECT
1
FROM users_blocks ub
WHERE ub.foreign_user_id = 1
AND ub.user_id = users.id)
)
AND ((chats1.user_id = 1
OR chats1.foreign_user_id = 1)
OR (chats1.user_id is NULL
AND chats1.foreign_user_id is NULL))
ORDER BY `users_chats`.`created` DESC
Basically, only successfully join if there's no more recent message. There are some better native solutions - TSQL (Microsoft SQL Server) has CROSS APPLY, which would be great here - but without knowing more about your DB layer, I can't be sure. You may want to considered re-architecting your chat structure:
Users(int id /*also other user info*/)
chats(int id, datetime date_initiated, bool /*or bit, or short int*/ is_active)
chat_users (int chat_id, int user_id)
chat_messages (int chat_id, int user_id /*author*/, datetime date_sent, varchar(n) message)
With a structure like that, you could get all your most recent messages like this:
SELECT *
FROM Users AS u
INNER JOIN chat_users AS cu
ON u.id = cu.user_id
INNER JOIN chats AS c
ON c.id = cu.chat_id
AND c.is_active = 1
INNER JOIN chat_messages AS m
ON m.chat_id = c.id
AND NOT EXISTS (
SELECT 1
FROM chat_messages AS m2
WHERE m2.chat_id = m.chat_id
AND m.date_sent < m2.date_sent
)
INNER JOIN Users as sender
ON m.user_id = sender.id
WHERE u.id = ###
ORDER BY m.date_sent DESC
You could even create a "Chat most recent message" view like:
CREATE VIEW Chat_Recent AS
SELECT * /* WHATEVER YOU LIKE */
FROM chats AS c
INNER JOIN chat_messages AS m
ON m.chat_id = c.id
AND NOT EXISTS (
SELECT 1
FROM chat_messages AS m2
WHERE m2.chat_id = m.chat_id
AND m.date_sent < m2.date_sent
)
INNER JOIN Users as sender
ON m.user_id = sender.id
Try MySQL MAX():
$this->db->join('(SELECT MAX(message) AS lastMsg FROM users_chats WHERE users_chats.user_id=users.id OR users_chats.foreign_user_id=users.id GROUP BY users.id)', 'left outer');
Then add the "lastMsg" on your select.
I'm working on the layered navigation module with Prestashop solution,
I'm trying to optimize a Sql query which create a tmp table to execute it and by this way create a bottleneck in mysql.
This is the query :
SELECT p.*, p.id_category_default, pl.available_later, pl.description_short, pl.link_rewrite, pl.name, i.id_image, il.legend, m.name manufacturer_name, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL 30 DAY)) > 0 AS new
FROM `ps_category_product` cp
LEFT JOIN ps_category c ON (c.id_category = cp.id_category)
LEFT JOIN `ps_product` p ON p.`id_product` = cp.`id_product`
LEFT JOIN ps_product_lang pl ON (pl.id_product = p.id_product)
LEFT JOIN ps_image i ON (i.id_product = p.id_product AND i.cover = 1)
LEFT JOIN ps_image_lang il ON (i.id_image = il.id_image AND il.id_lang = 2)
LEFT JOIN ps_manufacturer m ON (m.id_manufacturer = p.id_manufacturer)
WHERE p.`active` = 1 AND c.nleft >= 2 AND c.nright <= 29 AND c.active = 1 AND pl.id_lang = 2
AND p.id_product IN (74,78,130,146,168,169,178,195,...,297,302,1986,1987,1988,1993,1999,2000,2001)
GROUP BY p.id_product ORDER BY p.date_upd desc LIMIT 0,48
I know the tmp table is created because of the GROUP BY but I don't know how to remove it. If the same process could be done with PHP instead of SQL, it could be a solution.
Thanks in advance.