citus_stat_statements failing to extract partition key in some router queries
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
While running pgbench I tested citus_stat_statements, and found that one insert query has partition keys missing in the `citus_stat_statemeents` view
The Steps below are a bit complicated. I will simplify the steps to reproduce the problem when I have the time
## Steps to run pgbench:
```bash
#!/usr/bin/env bash
# provide a valid connection string with working citus_stat_statements
POSTGRES_URL=postgresql://citus:pass@machineaddress:5432/citus?sslmode=require
# create tables
pgbench -i -I dtp $POSTGRES_URL
# distribute tables
psql -c "SELECT create_distributed_table('pgbench_accounts', 'aid');" $POSTGRES_URL
psql -c "SELECT create_distributed_table('pgbench_history', 'aid');" $POSTGRES_URL
psql -c "SELECT create_distributed_table('pgbench_branches', 'bid');" $POSTGRES_URL
psql -c "SELECT create_distributed_table('pgbench_tellers', 'tid');" $POSTGRES_URL
# load data
pgbench -i -I gv -s $SCALE $POSTGRES_URL
# run pgbench for 5 minutes
pgbench -b select-only -b simple-update -b tpcb-like -c 32 -j 64 -P 10 -T 300 $POSTGRES_URL
```
## `citus_stat_statments` record
When I query citus_stat_statements, I see that its count is only 1 INSERT statement with missing partition_key column
```
citus=> SELECT * FROM citus_stat_statements WHERE query LIKE 'INSERT%';
-[ RECORD 1 ]-+-----------------------------------------------------------------------------------------------------
queryid | 1296220265436278941
userid | 16384
dbid | 16385
query | INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES ($1, $2, $3, $4, CURRENT_TIMESTAMP)
executor | router
partition_key |
calls | 4769
```
## `pg_stat_statements` record
```
citus=> SELECT * FROM pg_stat_statements WHERE query LIKE 'INSERT INTO pgbench_history%' ORDER BY calls DESC LIMIT 3;
-[ RECORD 1 ]-------+-----------------------------------------------------------------------------------------------------
userid | 16384
dbid | 16385
queryid | 1296220265436278941
query | INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES ($1, $2, $3, $4, CURRENT_TIMESTAMP)
calls | 229380582
total_time | 1693213860.54107
min_time | 0.2047
max_time | 1837.661
mean_time | 7.38167915426013
stddev_time | 21.759587092484
rows | 229380582
shared_blks_hit | 0
shared_blks_read | 0
shared_blks_dirtied | 0
shared_blks_written | 0
local_blks_hit | 0
local_blks_read | 0
local_blks_dirtied | 0
local_blks_written | 0
temp_blks_read | 0
temp_blks_written | 0
blk_read_time | 0
blk_write_time | 0
```
Contributor guide
Assessment
This issue has not been assessed yet.