提交 e9a86809 编写于 作者: K Karen Huddleston 提交者: Jamie McAtamney

Fix error with statistics restore when statistics already exist

Previously, if pg_statistic already contains statistics for
a given table column, attempting to insert those statistics
again during the restore would give a primary key error and
statistics would not be correctly restored.

Now, existing statistics are deleted just before inserting the
restore statistics, so there is no collision.
Signed-off-by: NJamie McAtamney <jmcatamney@pivotal.io>
上级 501dd328
......@@ -1634,13 +1634,18 @@ WHERE relname = '%s' AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspn
outfile.write("""--
-- Schema: %s, Table: %s, Attribute: %s
--
DELETE FROM pg_statistic WHERE starelid = %d AND staattnum = %d;
INSERT INTO pg_statistic VALUES (
%d::oid,
%d::smallint,
%f::real,
%d::integer,
%f::real,
""" % (nspname, relname, attname, starelid, staattnum, stanullfrac, stawidth, stadistinct))
""" % (nspname, relname, attname,
starelid, staattnum,
starelid, staattnum, stanullfrac, stawidth, stadistinct))
# If a typname starts with exactly one it describes an array type
# We can't restore statistics of array columns, so we'll zero and NULL everything out
......
......@@ -615,6 +615,9 @@ class RestoreDatabase(Operation):
if replace_toggle and "::smallint" in line:
line = " %s::smallint,\n" % new_attnum
replace_toggle = False
if replace_toggle and "DELETE FROM" in line:
line = re.sub("starelid = (\w+)", "starelid = %s" % new_oid, line)
line = re.sub("staattnum = (\w+)", "staattnum = %s" % new_attnum, line)
if print_toggle:
outfile.write(line)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册