Skip to content

Commit be40f24

Browse files
committed
Fix #29; Fix incorrect offset calculation
To calculate "offset" to store a new plan at, we should sum the lengths of the already stored plans within the memory plus the number of plans to accomodate for NULL character at the end of each plan. Instead, I used to sum up the lengths of all plans and add 1.
1 parent 7796bf4 commit be40f24

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

pg_show_plans.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ append_query_plan(ExplainState *es)
292292

293293
offset = 0;
294294
for (i = 0; i < nest_level; i++)
295-
offset += pgsp_cache->plan_len[i];
296-
if (nest_level >= 1)
297-
offset++; /* Point right after the '\0'. */
295+
offset += pgsp_cache->plan_len[i] + 1;
298296
space_left = max_plan_length - offset;
299297

300298
if (pgsp->plan_format == EXPLAIN_FORMAT_TEXT)
@@ -637,9 +635,7 @@ pg_show_plans(PG_FUNCTION_ARGS)
637635
* count offset to get the desired plan. */
638636
offset = 0;
639637
for (i = 0; i < curr_nest; i++)
640-
offset += pgvp_tmp_entry->plan_len[i];
641-
if (offset > 0)
642-
offset++;
638+
offset += pgvp_tmp_entry->plan_len[i] + 1;
643639

644640
MemSet(nulls, 0, sizeof(nulls));
645641
values[0] = Int32GetDatum(pgvp_tmp_entry->hash_key.pid);

0 commit comments

Comments
 (0)