mirror of
https://github.com/HypoPG/hypopg
synced 2026-05-23 09:08:45 +00:00
Add a new hypo_get_index() function.
This will be helpful in a following patch. The immediate effect is to fix a long standing small performance issue, as hypo_explain_get_index_name_hook didn't stop its loop once it found a matching entry.
This commit is contained in:
parent
0eca85f2aa
commit
0864fbe1fb
2 changed files with 25 additions and 19 deletions
|
|
@ -1116,36 +1116,41 @@ hypo_injectHypotheticalIndex(PlannerInfo *root,
|
|||
rel->indexlist = lcons(index, rel->indexlist);
|
||||
}
|
||||
|
||||
/* Return the hypothetical index name is indexId is ours, NULL otherwise, as
|
||||
/*
|
||||
* Return the stored hypothetical index for a given oid if any, NULL otherwise
|
||||
*/
|
||||
hypoIndex *
|
||||
hypo_get_index(Oid indexId)
|
||||
{
|
||||
ListCell *lc;
|
||||
|
||||
foreach(lc, hypoIndexes)
|
||||
{
|
||||
hypoIndex *entry = (hypoIndex *) lfirst(lc);
|
||||
|
||||
if (entry->oid == indexId)
|
||||
return entry;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Return the hypothetical index name ifs indexId is ours, NULL otherwise, as
|
||||
* this is what explain_get_index_name expects to continue his job.
|
||||
*/
|
||||
const char *
|
||||
hypo_explain_get_index_name_hook(Oid indexId)
|
||||
{
|
||||
char *ret = NULL;
|
||||
|
||||
if (isExplain)
|
||||
{
|
||||
/*
|
||||
* we're in an explain-only command. Return the name of the
|
||||
* hypothetical index name if it's one of ours, otherwise return NULL
|
||||
*/
|
||||
ListCell *lc;
|
||||
hypoIndex *index = NULL;
|
||||
|
||||
foreach(lc, hypoIndexes)
|
||||
{
|
||||
hypoIndex *entry = (hypoIndex *) lfirst(lc);
|
||||
index = hypo_get_index(indexId);
|
||||
|
||||
if (entry->oid == indexId)
|
||||
{
|
||||
ret = entry->indexname;
|
||||
}
|
||||
}
|
||||
if (index)
|
||||
return index->indexname;
|
||||
}
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (prev_explain_get_index_name_hook)
|
||||
return prev_explain_get_index_name_hook(indexId);
|
||||
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ PGDLLEXPORT Datum hypopg_get_indexdef(PG_FUNCTION_ARGS);
|
|||
PGDLLEXPORT Datum hypopg_reset_index(PG_FUNCTION_ARGS);
|
||||
|
||||
extern explain_get_index_name_hook_type prev_explain_get_index_name_hook;
|
||||
hypoIndex *hypo_get_index(Oid indexId);
|
||||
const char *hypo_explain_get_index_name_hook(Oid indexId);
|
||||
|
||||
void hypo_injectHypotheticalIndex(PlannerInfo *root,
|
||||
|
|
|
|||
Loading…
Reference in a new issue