diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index d43a3f10ec4..2ef11709255 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -2778,9 +2778,12 @@ get_tmp_table_costs(THD *thd, double row_count, uint row_size, bool blobs_used,
     double row_copy_cost= (add_copy_cost ?
                            tmp_table_optimizer_costs.row_copy_cost :
                            0);
+    double DISK_TEMPTABLE_MEM_LOOKUP_COST= (HEAP_TEMPTABLE_LOOKUP_COST*2/3);
     /* Disk based table */
     cost.lookup=          ((tmp_table_optimizer_costs.key_lookup_cost *
                             tmp_table_optimizer_costs.disk_read_ratio) +
+                           (DISK_TEMPTABLE_MEM_LOOKUP_COST *
+                             (1-tmp_table_optimizer_costs.disk_read_ratio)) +
                            row_copy_cost);
     cost.write=           cost.lookup;
     cost.create=          DISK_TEMPTABLE_CREATE_COST;
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc
index aafccdac447..f800e00176f 100644
--- a/sql/sql_explain.cc
+++ b/sql/sql_explain.cc
@@ -2257,6 +2257,12 @@ void Explain_table_access::print_explain_json(Explain_query *query,
     /* This is a non-merged semi-join table. Print its contents here */
     writer->add_member("materialized").start_object();
     writer->add_member("unique").add_ll(1);
+    writer->add_member("materialization_cost").add_double(sjm_nest->materialization_cost);
+    if (sjm_nest->scan_cost != 0.0)
+      writer->add_member("scan_cost").add_double(sjm_nest->scan_cost);
+    if (sjm_nest->lookup_cost != 0.0)
+      writer->add_member("lookup_cost").add_double(sjm_nest->lookup_cost);
+
     sjm_nest->print_explain_json(query, writer, is_analyze);
     writer->end_object();
   }
diff --git a/sql/sql_explain.h b/sql/sql_explain.h
index a8b56bb3d42..bf589a27ca1 100644
--- a/sql/sql_explain.h
+++ b/sql/sql_explain.h
@@ -155,6 +155,7 @@ class Explain_node : public Sql_alloc
 
 
 class Explain_table_access;
+class Explain_sj_mat;
 
 
 /* 
@@ -193,6 +194,19 @@ class Explain_basic_join : public Explain_node
 };
 
 
+class Explain_sj_mat: public Explain_basic_join
+{
+public:
+  Explain_sj_mat(MEM_ROOT *root) : 
+    Explain_basic_join(root), materialization_cost(0.0),
+    scan_cost(0.0), lookup_cost(0.0)
+  {}
+  
+  double materialization_cost;
+  double scan_cost;
+  double lookup_cost;
+};
+
 class Explain_aggr_node;
 /*
   EXPLAIN structure for a SELECT.
@@ -883,7 +897,7 @@ class Explain_table_access : public Sql_alloc
   */
   Item *pushed_index_cond;
 
-  Explain_basic_join *sjm_nest;
+  Explain_sj_mat *sjm_nest;
   
   /*
     This describes a possible filesort() call that is done before doing the
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index e49003a734f..46b7ab0ca33 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -31285,6 +31285,7 @@ int JOIN::save_explain_data_intern(Explain_query *output,
     JOIN_TAB* prev_bush_root_tab= NULL;
 
     Explain_basic_join *cur_parent= xpl_sel;
+    Explain_sj_mat *cur_sjm= NULL;
     
     for (JOIN_TAB *tab= first_explain_order_tab(join); tab;
          tab= next_explain_order_tab(join, tab))
@@ -31312,10 +31313,19 @@ int JOIN::save_explain_data_intern(Explain_query *output,
           /* 
             We've entered an SJ-Materialization nest. Create an object for it.
           */
-          if (!(cur_parent=
-                new (output->mem_root) Explain_basic_join(output->mem_root)))
+          if (!(cur_sjm=
+                new (output->mem_root) Explain_sj_mat(output->mem_root)))
             DBUG_RETURN(1);
 
+          cur_parent= cur_sjm;
+          SJ_MATERIALIZATION_INFO *mat_info= tab->emb_sj_nest->sj_mat_info;
+          cur_sjm->materialization_cost= mat_info->materialization_cost;
+          if (mat_info->is_sj_scan)
+            cur_sjm->scan_cost= mat_info->scan_cost;
+          else
+            cur_sjm->lookup_cost= mat_info->lookup_cost;
+
+
           JOIN_TAB *first_child= tab->bush_root_tab->bush_children->start;
           cur_parent->select_id=
             first_child->emb_sj_nest->sj_subq_pred->get_identifier();
@@ -31327,7 +31337,8 @@ int JOIN::save_explain_data_intern(Explain_query *output,
             that 'embeds the nest'
           */
           DBUG_ASSERT(tab->bush_children);
-          eta->sjm_nest= cur_parent;
+          eta->sjm_nest= cur_sjm;
+          cur_sjm= NULL;
           cur_parent= xpl_sel;
         }
       }
