# In Query Analytics, the same statement executed in different databases will only be counted once

**URL:** https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168
**Category:** PMM 2.x
**Created:** [August 3, 2023, 10:37am UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168 "2023-08-03T10:37:48Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![frank.pan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/frank.pan/32/19835_2.png) [@frank.pan](https://forums.percona.com/u/frank.pan)
#### Post date: [August 3, 2023, 10:37am UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/1 "2023-08-03T10:37:49Z")

</div>

## Description:

We found that in Query Analytics, the same statement executed in different databases will only be counted once.

## Steps to Reproduce:

Our database architecture uses MySQL’s sharding, for example, there are 8 databases named test0001 to test0008 in one instance, and each database has the same tables. For example:

```auto
use test0001;
select sleep(10) from t;
use test0002;
select sleep(10) from t;

```

In this case, Query Analytics only counts one `select sleep(10) from t`.

## Version:

PMM 2.37.1  
MySQL 5.7 + performance\_schema

---

<div class="post-metadata">

### Author: ![Roma\_Novikov](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/roma_novikov/32/1161_2.png) [@Roma\_Novikov](https://forums.percona.com/u/Roma_Novikov)
#### Post date: [August 3, 2023, 2:47pm UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/2 "2023-08-03T14:47:24Z")

</div>

Hi @frank.pan  
You should see only one Line in QAN for this query, but the count - should be from all databases (schema)  
You should be able to see schemas in QAN, and if you add filtering by then - the count of query execution should be specific for the selected schema.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/f/f685ba7fa3d164058b8e5aa93f94c6c6b5b3ac9f.png)

Additionally, the upcoming release next week will include an enhancement for [[PMM-6279] Query metadata not visible in new UI - Percona JIRA](https://jira.percona.com/browse/PMM-6279) that will improve the visibility of such scenarios.

---

<div class="post-metadata">

### Author: ![frank.pan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/frank.pan/32/19835_2.png) [@frank.pan](https://forums.percona.com/u/frank.pan)
#### Post date: [August 4, 2023, 2:19am UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/3 "2023-08-04T02:19:17Z")

</div>

Hi,

Here is my test:

```auto
mysql> use test1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select sleep(10) as qan from t limit 1;
+-----+
| qan |
+-----+
| 0 |
+-----+
1 row in set (10.00 sec)

mysql> use test2;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select sleep(10) as qan from t limit 1;
+-----+
| qan |
+-----+
| 0 |
+-----+
1 row in set (10.00 sec)

mysql>

```

Filter using the Sleep keyword after waiting for a period of time.

 ![1](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/6/66e4ab75cac01ae5e298f9228a71607d10cf7c94.png)

Where did I go wrong?

---

<div class="post-metadata">

### Author: ![Roma\_Novikov](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/roma_novikov/32/1161_2.png) [@Roma\_Novikov](https://forums.percona.com/u/Roma_Novikov)
#### Post date: [August 4, 2023, 7:27am UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/4 "2023-08-04T07:27:53Z")

</div>

@frank.pan , can you click on the Query and check the details?  
10 sec in the main view - is the average time for the query, mane as Query count = queries per second.

What is clear on your screen - is the first query hasn’t tracked the schema name (test1). This might be our bug or performance schema limitation.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/6/6ade0c56affcd1370143ef1fe748daa844a9b98e.png)

---

<div class="post-metadata">

### Author: ![frank.pan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/frank.pan/32/19835_2.png) [@frank.pan](https://forums.percona.com/u/frank.pan)
#### Post date: [August 4, 2023, 8:39am UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/5 "2023-08-04T08:39:26Z")

</div>

```plaintext
mysql> truncate table performance_schema.events_statements_summary_by_digest;
Query OK, 0 rows affected (0.01 sec)

mysql> use test1;
Database changed

mysql> select sleep(10) as qan2 from t limit 1;
+------+
| qan2 |
+------+
| 0 |
+------+
1 row in set (10.00 sec)

mysql> use test2;
Database changed

mysql> select sleep(10) as qan2 from t limit 1;
+------+
| qan2 |
+------+
| 0 |
+------+
1 row in set (10.03 sec)

```

 ![3](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/c/cc67718c02a6a38f78fb5a6c55e541f1c09c067a.png)

I think the reason is that PMM does not perform aggregated analysis on the same SQL queries from different databases.  
I don’t know if it’s correct.

---

<div class="post-metadata">

### Author: ![frank.pan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/frank.pan/32/19835_2.png) [@frank.pan](https://forums.percona.com/u/frank.pan)
#### Post date: [August 4, 2023, 8:49am UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/6 "2023-08-04T08:49:35Z")

</div>

This is the query result of events\_statements\_summary\_by\_digest.

```auto
mysql> select * from performance_schema.events_statements_summary_by_digest where digest_text like 'SELECT `sleep` (?) AS `qan2` FROM `t` LIMIT ? '\G
***************************1. row***************************
                SCHEMA_NAME: test1
                     DIGEST: 80498c1c7c6ed0f05789c9bfc29993d3
                DIGEST_TEXT: SELECT `sleep` (?) AS `qan2` FROM `t` LIMIT ? 
                 COUNT_STAR: 1
             SUM_TIMER_WAIT: 10001581443000
             MIN_TIMER_WAIT: 10001581443000
             AVG_TIMER_WAIT: 10001581443000
             MAX_TIMER_WAIT: 10001581443000
              SUM_LOCK_TIME: 131000000
                 SUM_ERRORS: 0
               SUM_WARNINGS: 0
          SUM_ROWS_AFFECTED: 0
              SUM_ROWS_SENT: 1
          SUM_ROWS_EXAMINED: 1
SUM_CREATED_TMP_DISK_TABLES: 0
     SUM_CREATED_TMP_TABLES: 0
       SUM_SELECT_FULL_JOIN: 0
 SUM_SELECT_FULL_RANGE_JOIN: 0
           SUM_SELECT_RANGE: 0
     SUM_SELECT_RANGE_CHECK: 0
            SUM_SELECT_SCAN: 1
      SUM_SORT_MERGE_PASSES: 0
             SUM_SORT_RANGE: 0
              SUM_SORT_ROWS: 0
              SUM_SORT_SCAN: 0
          SUM_NO_INDEX_USED: 1
     SUM_NO_GOOD_INDEX_USED: 0
                 FIRST_SEEN: 2023-08-04 16:33:29
                  LAST_SEEN: 2023-08-04 16:33:29
***************************2. row***************************
                SCHEMA_NAME: test2
                     DIGEST: 80498c1c7c6ed0f05789c9bfc29993d3
                DIGEST_TEXT: SELECT `sleep` (?) AS `qan2` FROM `t` LIMIT ? 
                 COUNT_STAR: 1
             SUM_TIMER_WAIT: 10021048186000
             MIN_TIMER_WAIT: 10021048186000
             AVG_TIMER_WAIT: 10021048186000
             MAX_TIMER_WAIT: 10021048186000
              SUM_LOCK_TIME: 47000000
                 SUM_ERRORS: 0
               SUM_WARNINGS: 0
          SUM_ROWS_AFFECTED: 0
              SUM_ROWS_SENT: 1
          SUM_ROWS_EXAMINED: 1
SUM_CREATED_TMP_DISK_TABLES: 0
     SUM_CREATED_TMP_TABLES: 0
       SUM_SELECT_FULL_JOIN: 0
 SUM_SELECT_FULL_RANGE_JOIN: 0
           SUM_SELECT_RANGE: 0
     SUM_SELECT_RANGE_CHECK: 0
            SUM_SELECT_SCAN: 1
      SUM_SORT_MERGE_PASSES: 0
             SUM_SORT_RANGE: 0
              SUM_SORT_ROWS: 0
              SUM_SORT_SCAN: 0
          SUM_NO_INDEX_USED: 1
     SUM_NO_GOOD_INDEX_USED: 0
                 FIRST_SEEN: 2023-08-04 16:33:39
                  LAST_SEEN: 2023-08-04 16:33:39
2 rows in set (0.00 sec)

mysql> 

```

---

<div class="post-metadata">

### Author: ![frank.pan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/frank.pan/32/19835_2.png) [@frank.pan](https://forums.percona.com/u/frank.pan)
#### Post date: [August 8, 2023, 3:20am UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/7 "2023-08-08T03:20:34Z")

</div>

Who could assist in resolving this issue? Thank you!

---

<div class="post-metadata">

### Author: ![steve.hoffman](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/steve.hoffman/32/66_2.png) [@steve.hoffman](https://forums.percona.com/u/steve.hoffman)
#### Post date: [August 8, 2023, 2:26pm UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/8 "2023-08-08T14:26:00Z")

</div>

As Roma suggested, you may have uncovered a bug and it’s best to submit a ticket via [https://jira.percona.com](https://jira.percona.com) against the PMM project, specifically the QAN component. You might also consider Percona for an active support contract. In that case, one call and your issue will get escalated and prioritized as a customer vs community report. DM me if you’re interested in learning more and I’ll connect you with our team to learn more about other benefits of being a customer.

---

<div class="post-metadata">

### Author: ![Roma\_Novikov](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/roma_novikov/32/1161_2.png) [@Roma\_Novikov](https://forums.percona.com/u/Roma_Novikov)
#### Post date: [August 25, 2023, 1:15pm UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/9 "2023-08-25T13:15:48Z")

</div>

Hello @frank.pan , thank you for providing the details and report. Based on the data provided, it appears to be a bug that is affecting multiple users. We will prioritize fixing this issue as it is considered a high-priority bug in QAN.

---

<div class="post-metadata">

### Author: ![frank.pan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/frank.pan/32/19835_2.png) [@frank.pan](https://forums.percona.com/u/frank.pan)
#### Post date: [May 6, 2024, 2:44am UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/10 "2024-05-06T02:44:06Z")

</div>

Hello, may I ask if there has been any progress on this issue or bug? I’ve tested with the latest version 2.41.2, and it seems that the problem still exists.

---

<div class="post-metadata">

### Author: ![Naresh9999](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/naresh9999/32/5568_2.png) [@Naresh9999](https://forums.percona.com/u/Naresh9999)
#### Post date: [May 6, 2024, 8:30am UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/11 "2024-05-06T08:30:00Z")

</div>

Hi @frank.pan

Did you submit a bug request regarding this issue?

---

<div class="post-metadata">

### Author: ![frank.pan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/frank.pan/32/19835_2.png) [@frank.pan](https://forums.percona.com/u/frank.pan)
#### Post date: [May 6, 2024, 10:06am UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/12 "2024-05-06T10:06:57Z")

</div>

Yes, I’ve submitted a bug report [PMM-12413](https://perconadev.atlassian.net/browse/PMM-12413), but the progress seems a bit slow? Any idea when it might be fixed? Thanks.

---

<div class="post-metadata">

### Author: ![frank.pan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/frank.pan/32/19835_2.png) [@frank.pan](https://forums.percona.com/u/frank.pan)
#### Post date: [July 5, 2024, 3:43am UTC](https://forums.percona.com/t/in-query-analytics-the-same-statement-executed-in-different-databases-will-only-be-counted-once/24168/13 "2024-07-05T03:43:35Z")

</div>

Could you please provide any information regarding a resolution plan for this bug? We’ve been awaiting a fix for quite some time now.
