diff --git a/src/box/alter.cc b/src/box/alter.cc
index 92f1d5b221caa1da074746889535c71226fd2d61..0f8ba082a32f6c0ffa033818af1af4cbab68f9ed 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -581,6 +581,7 @@ space_swap_fk_constraints(struct space *new_space, struct space *old_space)
 		   &old_space->child_fk_constraint);
 	rlist_swap(&new_space->parent_fk_constraint,
 		   &old_space->parent_fk_constraint);
+	SWAP(new_space->fk_constraint_mask, old_space->fk_constraint_mask);
 }
 
 /**
diff --git a/test/sql/foreign-keys.result b/test/sql/foreign-keys.result
index b8ff8f145251bc0b862bb87a9fe1ecfb2ba01c64..29538e8160d225a50f02bfe10ab52b52c5d78770 100644
--- a/test/sql/foreign-keys.result
+++ b/test/sql/foreign-keys.result
@@ -457,5 +457,43 @@ t1:drop()
 t2:drop()
 ---
 ...
+-- gh-4495: space alter resulted in foreign key mask reset.
+-- Which in turn led to wrong byte-code generation. Make sure
+-- that alter of space doesn't affect result of query execution.
+--
+box.execute("CREATE TABLE t (id TEXT PRIMARY KEY, a INTEGER NOT NULL);")
+---
+- row_count: 1
+...
+box.execute("CREATE TABLE s (t_id TEXT PRIMARY KEY, a INTEGER NOT NULL, FOREIGN KEY(t_id) REFERENCES t(id) ON DELETE CASCADE);")
+---
+- row_count: 1
+...
+box.space.T:insert({'abc', 1})
+---
+- ['abc', 1]
+...
+box.space.S:insert({'abc', 1})
+---
+- ['abc', 1]
+...
+box.execute("CREATE INDEX i ON s (t_id);")
+---
+- row_count: 1
+...
+box.execute("DELETE FROM t WHERE id = 'abc';")
+---
+- row_count: 1
+...
+box.space.T:select()
+---
+- []
+...
+box.space.S:drop()
+---
+...
+box.space.T:drop()
+---
+...
 --- Clean-up SQL DD hash.
 -test_run:cmd('restart server default with cleanup=1')
diff --git a/test/sql/foreign-keys.test.lua b/test/sql/foreign-keys.test.lua
index 4ac5999d7cbce6a61cd124cb9081a8e56532414f..d2dd88d2809b6a0521dd8d057aafefcc3efafb81 100644
--- a/test/sql/foreign-keys.test.lua
+++ b/test/sql/foreign-keys.test.lua
@@ -194,5 +194,20 @@ box.execute("ALTER TABLE t2 ADD CONSTRAINT fk FOREIGN KEY (id) REFERENCES t1;")
 t1:drop()
 t2:drop()
 
+-- gh-4495: space alter resulted in foreign key mask reset.
+-- Which in turn led to wrong byte-code generation. Make sure
+-- that alter of space doesn't affect result of query execution.
+--
+box.execute("CREATE TABLE t (id TEXT PRIMARY KEY, a INTEGER NOT NULL);")
+box.execute("CREATE TABLE s (t_id TEXT PRIMARY KEY, a INTEGER NOT NULL, FOREIGN KEY(t_id) REFERENCES t(id) ON DELETE CASCADE);")
+box.space.T:insert({'abc', 1})
+box.space.S:insert({'abc', 1})
+box.execute("CREATE INDEX i ON s (t_id);")
+box.execute("DELETE FROM t WHERE id = 'abc';")
+box.space.T:select()
+
+box.space.S:drop()
+box.space.T:drop()
+
 --- Clean-up SQL DD hash.
 -test_run:cmd('restart server default with cleanup=1')