Search on Multiple index gives wrong total_found Result ( Sphinx 2.X )

StackOverflow https://stackoverflow.com/questions/21600887

  •  07-10-2022
  •  | 
  •  

Вопрос

I am not sure, I am right or wrong.

I have two index x_person , y_person .

If i query on x_person

SELECT * FROM x_person WHERE is_active = 0 LIMIT 0,1;

mysql> show meta;
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| total         | 1000   |
| total_found   | 131541 |
| time          | 0.005  |
+---------------+--------+
3 rows in set (0.00 sec)

And Querying in y_person :

SELECT * FROM y_person WHERE is_active = 0 LIMIT 0,1;Show meta;

mysql> show meta;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| total         | 1000  |
| total_found   | 34733 |
| time          | 0.002 |
+---------------+-------+
3 rows in set (0.00 sec)

Assuming if i select x_person and y_person index together, the total_match should be 131541+34733 = 166274

SELECT * FROM x_person,y_person WHERE is_active = 0 LIMIT 0,1;


mysql> show meta;
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| total         | 1000   |
| total_found   | 165552 |
| time          | 0.008  |
+---------------+--------+
3 rows in set (0.00 sec)

Here i got total_found = 165552. Can any one explain Why this is not showing same 'total_found' Number ?

Это было полезно?

Решение

Sphinx searches both of those indexes, and makes a 'UNION' of the results. Adding them together.

131541 + 34733 = 166274. Which is roughly 165552 

The slight difference could be down to

  1. total_found is often an approximation. So wont exactly add up.

  2. Duplicate ids. If the same doc_id, is found in each index, it will only be returned ONCE in the final resultset. total_found will reflect this 'deduplication' (but again only approximatly)

Can make it less of an approximation, by raising max_matches, it its big enough to encompass the whole resultset, the figure will be exact.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top