diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index dcf1f0cfc798fa1fb865c60835c178b66bd262d7..ea69eb72b513410749208517b1e2a44f8bde1378 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -3520,7 +3520,11 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
 	  continue;
       }
 
-      *save_pos= *use;
+#ifdef HAVE_purify
+      /* Valgrind complains about overlapped memcpy when save_pos==use. */
+      if (save_pos != use)
+#endif
+        *save_pos= *use;
       prev=use;
       found_eq_constant= !use->used_tables;
       /* Save ptr to first use */