CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Search results display incorrect record count
Pages: [1]

Author Topic: Search results display incorrect record count  (Read 3116 times)

LMKWeb

  • I post occasionally
  • **
  • Posts: 43
  • Karma: 1
  • CiviCRM version: 4.2.6
  • CMS version: Joomla 2.5.8
Search results display incorrect record count
December 29, 2011, 11:26:39 am
I ran a search to get a count for how many contacts I have in a set of groups, and the number it shows as a result is very different from the actual result (530 vs 303). I've attached a screen shot showing the issue. Can anyone clue me in on how to fix this? I'm using Joomla 1.7 and CiviCRM 4.0. Thanks!

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Search results display incorrect record count
December 29, 2011, 12:01:19 pm
Can you replicate this on http://sandbox.joomla.civicrm.org

Kurund
Found this reply helpful? Support CiviCRM

LMKWeb

  • I post occasionally
  • **
  • Posts: 43
  • Karma: 1
  • CiviCRM version: 4.2.6
  • CMS version: Joomla 2.5.8
Re: Search results display incorrect record count
December 29, 2011, 01:32:56 pm
I was not able to duplicate the same issue. But I did note a secondary issue - I set the results to show 25 per page, but it actually showed 20 on page 1 and 24 on page 2 (out of a total 61 results that were found in the search).  I ran a search using a different set of groups, to see if I could replicate my issue, and that time the results displayed the correct amount of results per page.  I'm not sure what to think.

LMKWeb

  • I post occasionally
  • **
  • Posts: 43
  • Karma: 1
  • CiviCRM version: 4.2.6
  • CMS version: Joomla 2.5.8
Re: Search results display incorrect record count
January 04, 2012, 01:40:47 pm
Just wanted to bump this - any ideas for what could be causing the count disparity? I was thinking it could be because I've made some changes in the MySQL database - namely deleting records of group removals, because the glitch that causes removed groups to show up on a data export was causing serious problems. But I'm not sure where the count number is coming from, so I don't know where to look to fix it.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Search results display incorrect record count
January 04, 2012, 02:30:51 pm
I can confirm that this is a problem we have noted before. I think it might be the join on groups that differs between the count query & the select query - possibly as relates to people who have been in & out of a group.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

LMKWeb

  • I post occasionally
  • **
  • Posts: 43
  • Karma: 1
  • CiviCRM version: 4.2.6
  • CMS version: Joomla 2.5.8
Re: Search results display incorrect record count
January 04, 2012, 04:15:05 pm
That sounds like it could be the cause - we do have a lot of group activity, but because I've deleted all of the subscription history related to removals, there's really no way for us to check the numbers and see if there's a correlation.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Search results display incorrect record count
January 04, 2012, 04:35:05 pm
Something else I remember causing issues was address / phone / email fields with more than one primary - try this query

SELECT contact_id, count(id) as c
FROM civicrm_phone
WHERE is_primary =1
GROUP By contact_id
HAVING c > 1
ORDER BY c DESC
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Search results display incorrect record count
January 08, 2012, 12:51:27 am
I couldn't find a fix for this but it seems to work on the sandbox yet on 3.4.6 / 4.0.6 codebase it didn't make sense that it would ever work correctly.

In the case I looked into the join table is memberships but there are many that would produce the same symptoms

The search I was seeing for counting contacts with memberhships of more than one type was

SELECT count(*)  FROM civicrm_contact contact_a
LEFT JOIN civicrm_membership ON civicrm_membership.contact_id = contact_a.id  LEFT JOIN civicrm_contribution_recur ccr ON ( civicrm_membership.contribution_recur_id = ccr.id ) WHERE   civicrm_membership.membership_type_id IN ('27','26','29','34','14','30','32','31','35')  AND civicrm_membership.is_test = 0 )  AND (contact_a.is_deleted = 0)

There is no distinct or Group By and some contacts have more than one membership so the count will always be wrong.

By comparison the actual retrieval query ended in GROUP BY contact_a.id & hence returned the correct amount.

So, the COUNT is always wrong & the amount exported is correct.

I searched in JIRA & in the code for a fix that may have taken place but didn't find it - however, I * think* this must have been fixed for 4.1.

Either that or the issue is affected by the use of ACLs on the site. However I was testing with a user with 'view all contacts'

I will attach the backtrace on the 2 queries in case it's of use.
« Last Edit: January 08, 2012, 12:53:47 am by Eileen »
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Search results display incorrect record count
January 08, 2012, 12:44:00 pm

this was a reported bug and as been fixed in recent versions of 3.4.x / 4.0.x

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Search results display incorrect record count
January 08, 2012, 01:28:59 pm
Any idea of the JIRA - I couldn't find it.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

LMKWeb

  • I post occasionally
  • **
  • Posts: 43
  • Karma: 1
  • CiviCRM version: 4.2.6
  • CMS version: Joomla 2.5.8
Re: Search results display incorrect record count
January 08, 2012, 01:38:06 pm
Quote from: Donald Lobo on January 08, 2012, 12:44:00 pm

this was a reported bug and as been fixed in recent versions of 3.4.x / 4.0.x

lobo

We're running 4.0.7, but still experiencing the issue.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Search results display incorrect record count
February 13, 2012, 05:46:50 pm
Am also investigating a complaint of this in 3.4.7
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

gastrit

  • I post occasionally
  • **
  • Posts: 60
  • Karma: 2
  • CiviCRM version: 4.2.2
  • CMS version: 7.8
  • MySQL version: 5.1.41
  • PHP version: 5.3.2
Re: Search results display incorrect record count
February 24, 2012, 01:16:52 am
Hi!

I also experienced this issue on 4.07 and drupal 7.8. For me it only happened for groups with children groups.

Look at http://issues.civicrm.org/jira/browse/CRM-7186 for more info

// Jonas

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Search results display incorrect record count
February 27, 2012, 05:53:07 pm
I hit another permutation on this - I found that the left join on our ACL hook (multisite module) was causing the extra records.

I'm not sure what the 4.1 fixes affecting this are but what I saw looking at the code is that the advanced search query is quite expensive (depending on the criteria) & it is run 4 times:

1) Get the Pager
2) Get the count
3) Get the contacts to show
4) Get all eligible contact ids & stash in the prevnext cache table.

It seems that it would make sense to do #4 first & use it to reduce the load of the other 3 queries. There would need to be some tweaks on the index of the table.

In the iterim I have applied the following to make the count correct on our site - it gets the count of the cached items.


Code: [Select]
Index: sites/all/modules/civicrm/CRM/Core/Selector/Controller.php
===================================================================
--- sites/all/modules/civicrm/CRM/Core/Selector/Controller.php (revision 1627)
+++ sites/all/modules/civicrm/CRM/Core/Selector/Controller.php (working copy)
@@ -341,7 +341,11 @@
             if ($this->_output & self::SESSION) {
                 $this->_store->set( "{$this->_prefix}columnHeaders", $columnHeaders );
                 $this->_store->set( "{$this->_prefix}rows"         , $rows          );
-                $this->_store->set( "{$this->_prefix}rowCount"     , $this->_total  );
+                $this->_store->set( "{$this->_prefix}rowCount"     ,
+                             CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) FROM
+                             civicrm_prevnext_cache
+                             WHERE cacheKey = 'civicrm search {$this->_object->_formValues['qfKey']}'")  );
+
                 $this->_store->set( "{$this->_prefix}rowsEmpty"    , $rowsEmpty     );
                 $this->_store->set( "{$this->_prefix}qill"         , $qill          );
                 $this->_store->set( "{$this->_prefix}summary"      , $summary       );
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Rar9

  • I’m new here
  • *
  • Posts: 23
  • Karma: 0
    • Asset-Trade
  • CiviCRM version: 4.15
  • CMS version: Drupal 7.15
  • MySQL version: 5.1.63-0ubuntu0.10.04.1
  • PHP version: 5.3.10-1ubuntu2ppa7~lucid
Re: Search results display incorrect record count
April 11, 2012, 01:43:13 am
I have the same problem with Drupal 7 and CiviCRM 4.1.1

For one specific Group I get 29 results but only one Contact is showing.  This is only the case if all contact should get displayed.. which is the standard.

I can normal see them by furhter selcting them by the give A->Z.  If I press ALL i again only get one entry to show.

If I select all and Map them they get mapped correctly.

Is that some sort of FIX?

Cheers
Rar9
« Last Edit: April 11, 2012, 02:26:57 am by Rar9 »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Search results display incorrect record count

This forum was archived on 2017-11-26.