citusdata / citusdata/citus

Sticky Concept in citus_stat_statements.

Open
#7,040 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
12.8k
Forks
794
Avg merge
2d 14h
Merged PRs (30d)
31

Description

> I studied sticky concept in pg_stat_statements and got the idea how it works. The citus_stat_statements is implemented with pg_stat_statements as reference. But i feel sticky concept is not clear in citus_stat_statements.

- Actually when the calls for an entry is zero, then it is considered as sticky. If the connection to the server is lost (inside CitusQueryStatsExecutorsEntry) after adding an entry in queryStatsHash (i.e after execution of CitusQueryStatsEntryAlloc() ), then there is chance where entry->calls is zero. Actually this would be the rare case. So are there any ways where entry->calls is zero?
- The function CitusQueryStatsEntryAlloc() is called in two functions. In both the functions, it is called with sticky parameter as false. Then what is the case where sticky parameter is true and what is the purpose of sticky in citus_stat_statements?
- And also, the usage is not incremented when the query is executed more than one time. Is this the way how it works or it is a bug?
- In the implementation of CitusQueryStatsEntryAlloc(), inside the if check the entry->usage is initialised with some value, again the value is reinitialised to zero outside the if check. I think there is no use of initialising entry->usage.
```static QueryStatsEntry *
CitusQueryStatsEntryAlloc(QueryStatsHashKey *key, bool sticky)
{
bool found;
long StatStatementsMaxLong = StatStatementsMax;

/* Make space if needed */
while (hash_get_num_entries(queryStatsHash) >= StatStatementsMaxLong)
{
CitusQueryStatsEntryDealloc();
}

/* Find or create an entry with desired hash code */
QueryStatsEntry *entry = (QueryStatsEntry *) hash_search(queryStatsHash, key,
HASH_ENTER, &found);

if (!found)
{
/* New entry, initialize it */

/* set the appropriate initial usage count */
entry->usage = sticky ? queryStats->cur_median_usage : USAGE_INIT;

/* re-initialize the mutex each time ... we assume no one using it */
SpinLockInit(&entry->mutex);
}

entry->calls = 0;
entry->usage = (0.0);

return entry;
}
```
I expect that there should be some changes in the code. Can you clarify the doubts regarding citus_stat_statements?
Citus Version used : 12.0-1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.