Skip to content

Commit

Permalink
Only close relation when it was actually opened
Browse files Browse the repository at this point in the history
  • Loading branch information
PJMODOS committed Mar 30, 2017
1 parent 230bf1b commit 8e4098d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pglogical_apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,12 @@ handle_insert(StringInfo s)
if (rel != last_insert_rel)
{
multi_insert_finish();
last_insert_rel = rel;
/* Fall through to normal insert. */
}
else
{
apply_api.multi_insert_add_tuple(rel, &newtup);
last_insert_rel_cnt++;
return;
}
}
Expand All @@ -409,8 +410,11 @@ handle_insert(StringInfo s)
last_insert_rel = rel;
last_insert_rel_cnt = 0;
}
else if (last_insert_rel_cnt++ > MIN_MULTI_INSERT_TUPLES)
else if (last_insert_rel_cnt++ >= MIN_MULTI_INSERT_TUPLES)
{
use_multi_insert = true;
last_insert_rel_cnt = 0;
}
}

/* Normal insert. */
Expand Down Expand Up @@ -453,7 +457,7 @@ handle_insert(StringInfo s)
static void
multi_insert_finish(void)
{
if (use_multi_insert)
if (use_multi_insert && last_insert_rel_cnt)
{
apply_api.multi_insert_finish(last_insert_rel);
pglogical_relation_close(last_insert_rel, NoLock);
Expand Down

0 comments on commit 8e4098d

Please sign in to comment.