HTML Logo by World Wide Web Consortium ( Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS. ocPortal 9 is superseded by Composr 10.

Head over to for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.

Unfortunately a query has failed [SELECT COUNT(DISTINCT the_zone,the_page)

Login / Search

 [ Join | More ]
#101758 (In Topic #19958)

Your error seems to match a known and fixed bug in MySQL.

The full error is something like:
Unfortunately a query has failed [SELECT COUNT(DISTINCT the_zone,the_page) FROM ocp_comcode_pages WHERE the_zone<>'!' LIMIT 1] [Out of memory (Needed 8388512 bytes)]

How did this happen?

The bug description is as follows…

Your server is running MySQL 5.0.96 (approximate).

MySQL 5.0 ended it's extended support period on January 9, 2012. It should be upgraded.

This is caused by a bug in MySQL. The MySQL bug was never nailed down, but must have been fixed by someone at some point. Here is the bug report:
MySQL Bugs: #27023: out of memory error with COUNT(DISTINCT IF(...))

This OcCLE transcript illustrates the bug:


:print_r($GLOBALS['SITE_DB']->query("SELECT DISTINCT the_zone FROM ocp_comcode_pages"));:

    [0] => Array
            [the_zone] =>

    [1] => Array
            [the_zone] => adminzone

    [2] => Array
            [the_zone] => adminzone/

    [3] => Array
            [the_zone] => cms

    [4] => Array
            [the_zone] => feedback

    [5] => Array
            [the_zone] => forum

    [6] => Array
            [the_zone] => site

    [7] => Array
            [the_zone] => site/


:print_r($GLOBALS['SITE_DB']->query("SELECT COUNT(DISTINCT the_zone) FROM ocp_comcode_pages"));:

Unfortunately a query has failed [SELECT COUNT(DISTINCT the_zone) FROM ocp_comcode_pages] [Out of memory (Needed 8388572 bytes)]

The myisam_sort_buffer_size limit of 8MB is exceeded, even when dealing with just 8 very short rows in a very simple query.

How do I fix it?

Your server admin should upgrade MySQL.

A non-supported workaround is using this replacement line is sources/hooks/systems/do_next_menus/core.php:


   (has_specific_permission(get_member(),'edit_highrange_content')||has_specific_permission(get_member(),'edit_own_highrange_content'))?array('cms','comcode_page_edit',array('cms_comcode_pages',array('type'=>'misc'),get_module_zone('cms_comcode_pages')),do_lang_tempcode('ITEMS_HERE',do_lang_tempcode('_COMCODE_PAGES'),make_string_tempcode(escape_html(integer_format($GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM (SELECT DISTINCT the_zone,the_page FROM '.get_table_prefix().'comcode_pages WHERE '.db_string_not_equal_to('the_zone','!').') x'))))),('DOC_COMCODE_PAGE_EDIT')):NULL,
There may be many other problems though, and it is insecure to run old MySQL versions.

Become a fan of Composr on Facebook or add me as a friend. Add me on on Twitter. Support me on Patreon
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
1 guests and 0 members have just viewed this: None