1
- /* Copyright (c) 2010, 2017 , Oracle and/or its affiliates. All rights reserved.
1
+ /* Copyright (c) 2010, 2019 , Oracle and/or its affiliates. All rights reserved.
2
2
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
@@ -566,8 +566,8 @@ void JOIN_CACHE::filter_virtual_gcol_base_cols()
566
566
continue ;
567
567
568
568
const uint index = tab->effective_index ();
569
- if ( index != MAX_KEY &&
570
- table->index_contains_some_virtual_gcol (index ) &&
569
+ const bool cov_index =
570
+ index != MAX_KEY && table->index_contains_some_virtual_gcol (index ) &&
571
571
/*
572
572
There are two cases:
573
573
- If the table scan uses covering index scan, we can get the value
@@ -577,24 +577,38 @@ void JOIN_CACHE::filter_virtual_gcol_base_cols()
577
577
After restore the base columns, the value of virtual generated
578
578
columns can be calculated correctly.
579
579
*/
580
- table->covering_keys .is_set (index ))
580
+ table->covering_keys .is_set (index );
581
+
582
+ if (!(cov_index || tab->dynamic_range ())) continue ;
583
+
584
+ /*
585
+ Save of a copy of table->read_set in save_read_set so that it can be
586
+ restored. tmp_set cannot be used as recipient for this as it's already
587
+ used in other parts of JOIN_CACHE::init().
588
+ */
589
+ auto bitbuf =
590
+ (my_bitmap_map *)alloc_root (tab->table ()->in_use ->mem_root ,
591
+ table->s ->column_bitmap_size );
592
+ auto save_read_set = (MY_BITMAP *)alloc_root (tab->table ()->in_use ->mem_root ,
593
+ sizeof (MY_BITMAP));
594
+ bitmap_init (save_read_set, bitbuf, table->s ->fields , false );
595
+ bitmap_copy (save_read_set, table->read_set );
596
+ /*
597
+ restore_virtual_gcol_base_cols() will need old bitmap so we save a
598
+ reference to it.
599
+ */
600
+ save_read_set_for_gcol.insert (std::make_pair (tab, save_read_set));
601
+ if (cov_index)
581
602
{
582
- DBUG_ASSERT (bitmap_is_clear_all (&table->tmp_set ));
583
- // Keep table->read_set in tmp_set so that it can be restored
584
- bitmap_copy (&table->tmp_set , table->read_set );
585
603
bitmap_clear_all (table->read_set );
586
604
table->mark_columns_used_by_index_no_reset (index , table->read_set );
587
605
if (table->s ->primary_key != MAX_KEY)
588
606
table->mark_columns_used_by_index_no_reset (table->s ->primary_key ,
589
607
table->read_set );
590
- bitmap_intersect (table->read_set , &table-> tmp_set );
608
+ bitmap_intersect (table->read_set , save_read_set );
591
609
}
592
610
else if (tab->dynamic_range ())
593
611
{
594
- DBUG_ASSERT (bitmap_is_clear_all (&table->tmp_set ));
595
- // Keep table->read_set in tmp_set so that it can be restored
596
- bitmap_copy (&table->tmp_set , table->read_set );
597
-
598
612
filter_gcol_for_dynamic_range_scan (tab);
599
613
}
600
614
}
@@ -614,10 +628,11 @@ void JOIN_CACHE::restore_virtual_gcol_base_cols()
614
628
if (table->vfield == NULL )
615
629
continue ;
616
630
617
- if (!bitmap_is_clear_all (&table->tmp_set ))
631
+ auto saved = save_read_set_for_gcol.find (tab);
632
+ if (saved != save_read_set_for_gcol.end ())
618
633
{
619
- bitmap_copy (table-> read_set , &table-> tmp_set );
620
- bitmap_clear_all (& table->tmp_set );
634
+ DBUG_ASSERT (! bitmap_is_clear_all (saved-> second ) );
635
+ bitmap_copy ( table->read_set , saved-> second );
621
636
}
622
637
}
623
638
}
0 commit comments