@@ -63,6 +63,24 @@ struct ahi_node {
63
63
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
64
64
};
65
65
66
+ template <typename UnaryPred>
67
+ inline ahi_node *btr_sea::hash_chain::find (UnaryPred u) const noexcept
68
+ {
69
+ ahi_node *node= first;
70
+ while (node && !u (node))
71
+ node= node->next ;
72
+ return node;
73
+ }
74
+
75
+ template <typename UnaryPred>
76
+ inline ahi_node **btr_sea::hash_chain::search (UnaryPred u) noexcept
77
+ {
78
+ ahi_node **prev= &first;
79
+ while (!u (*prev))
80
+ prev= &(*prev)->next ;
81
+ return prev;
82
+ }
83
+
66
84
inline void btr_sea::partition::init () noexcept
67
85
{
68
86
latch.SRW_LOCK_INIT (btr_search_latch_key);
@@ -108,6 +126,16 @@ inline void btr_sea::partition::free() noexcept
108
126
blocks_mutex.destroy ();
109
127
}
110
128
129
+ inline void btr_sea::hash_table::create (ulint n) noexcept
130
+ {
131
+ n_cells= ut_find_prime (n);
132
+ const size_t size= MY_ALIGN (pad (n_cells) * sizeof *array,
133
+ CPU_LEVEL1_DCACHE_LINESIZE);
134
+ void *v= aligned_malloc (size, CPU_LEVEL1_DCACHE_LINESIZE);
135
+ memset_aligned<CPU_LEVEL1_DCACHE_LINESIZE>(v, 0 , size);
136
+ array= static_cast <hash_chain*>(v);
137
+ }
138
+
111
139
inline void btr_sea::partition::alloc (ulint hash_size) noexcept
112
140
{
113
141
table.create (hash_size);
@@ -665,8 +693,8 @@ void btr_sea::partition::insert(uint32_t fold, const rec_t *rec) noexcept
665
693
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
666
694
ut_ad (btr_search.enabled );
667
695
668
- ahi_node **prev= table.cell_get (fold)->
669
- search (&ahi_node::next, [fold](const ahi_node *node)
696
+ ahi_node **prev= table.cell_get (fold).
697
+ search ([fold](const ahi_node *node)
670
698
{ return !node || node->fold == fold; });
671
699
ahi_node *node= *prev;
672
700
@@ -761,8 +789,8 @@ buf_block_t *btr_sea::partition::cleanup_after_erase(ahi_node *erase) noexcept
761
789
{
762
790
/* Shrink the allocation by replacing the erased element with the top. */
763
791
*erase= *top;
764
- ahi_node **prev= table.cell_get (top->fold )->
765
- search (&ahi_node::next, [top](const ahi_node *n) { return n == top; });
792
+ ahi_node **prev= table.cell_get (top->fold ).
793
+ search ([top](const ahi_node *n) { return n == top; });
766
794
*prev= erase;
767
795
}
768
796
@@ -805,12 +833,12 @@ static void ha_remove_all_nodes_to_page(btr_sea::partition &part,
805
833
uint32_t fold, const page_t *page)
806
834
noexcept
807
835
{
808
- hash_cell_t * cell= part.table .cell_get (fold);
836
+ btr_sea::hash_chain & cell= part.table .cell_get (fold);
809
837
const uintptr_t page_size{srv_page_size};
810
838
811
839
rewind:
812
840
ahi_node **prev=
813
- cell-> search (&ahi_node::next, [page,page_size](const ahi_node *node)
841
+ cell. search ([page,page_size](const ahi_node *node)
814
842
{ return !node || (uintptr_t (node->rec ) ^ uintptr_t (page)) < page_size; });
815
843
816
844
if (ahi_node *node= *prev)
@@ -824,7 +852,7 @@ static void ha_remove_all_nodes_to_page(btr_sea::partition &part,
824
852
}
825
853
826
854
/* Check that all nodes really got deleted */
827
- ut_ad (!cell-> find (&ahi_node::next, [page](const ahi_node* node)
855
+ ut_ad (!cell. find ([page](const ahi_node* node)
828
856
{ return page_align (node->rec ) == page; }));
829
857
}
830
858
@@ -835,8 +863,8 @@ inline bool btr_sea::partition::erase(uint32_t fold, const rec_t *rec) noexcept
835
863
#endif
836
864
ut_ad (btr_search.enabled );
837
865
838
- ahi_node **prev= table.cell_get (fold)->
839
- search (&ahi_node::next, [rec](const ahi_node *node)
866
+ ahi_node **prev= table.cell_get (fold).
867
+ search ([rec](const ahi_node *node)
840
868
{ return !node || node->rec == rec; });
841
869
842
870
if (ahi_node *node= *prev)
@@ -862,7 +890,8 @@ updates the pointer to data if found.
862
890
@param data pointer to the data
863
891
@param new_data new pointer to the data
864
892
@return whether the element was found */
865
- static bool ha_search_and_update_if_found(hash_table_t *table, uint32_t fold,
893
+ static bool ha_search_and_update_if_found(btr_sea::hash_table *table,
894
+ uint32_t fold,
866
895
const rec_t *data,
867
896
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
868
897
/* * block containing new_data */
@@ -875,9 +904,8 @@ static bool ha_search_and_update_if_found(hash_table_t *table, uint32_t fold,
875
904
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
876
905
ut_ad (btr_search.enabled );
877
906
878
- if (ahi_node *node= table->cell_get (fold)->
879
- find (&ahi_node::next, [data](const ahi_node *node)
880
- { return node->rec == data; }))
907
+ if (ahi_node *node= table->cell_get (fold).
908
+ find ([data](const ahi_node *node){ return node->rec == data; }))
881
909
{
882
910
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
883
911
if (node->block != new_block)
@@ -1027,9 +1055,8 @@ btr_search_guess_on_hash(
1027
1055
return false ;
1028
1056
}
1029
1057
1030
- const ahi_node *node= part.table .cell_get (fold)->
1031
- find (&ahi_node::next, [fold](const ahi_node* node)
1032
- { return node->fold == fold; });
1058
+ const ahi_node *node= part.table .cell_get (fold).
1059
+ find ([fold](const ahi_node* node){ return node->fold == fold; });
1033
1060
1034
1061
if (!node)
1035
1062
{
@@ -1783,17 +1810,18 @@ void btr_search_update_hash_on_insert(btr_cur_t *cursor, bool reorg) noexcept
1783
1810
# if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1784
1811
__attribute__ ((nonnull))
1785
1812
/* * @return whether a range of the cells is valid */
1786
- static bool ha_validate(const hash_table_t *table,
1813
+ static bool ha_validate(const btr_sea::hash_table *table,
1787
1814
ulint start_index, ulint end_index)
1788
1815
{
1789
1816
ut_a (start_index <= end_index);
1790
1817
ut_a (end_index < table->n_cells );
1791
1818
1792
1819
bool ok= true ;
1793
1820
1821
+ /* FIXME: skip latches */
1794
1822
for (ulint i= start_index; i <= end_index; i++)
1795
1823
{
1796
- for (auto node= static_cast <const ahi_node*>(table->array [i].node ); node;
1824
+ for (auto node= static_cast <const ahi_node*>(table->array [i].first ); node;
1797
1825
node= node->next )
1798
1826
{
1799
1827
if (table->calc_hash (node->fold ) != i) {
@@ -1850,7 +1878,7 @@ static bool btr_search_hash_table_validate(THD *thd, ulint hash_table_id)
1850
1878
btr_sea::partition& part = btr_search.parts [hash_table_id];
1851
1879
1852
1880
cell_count = part.table .n_cells ;
1853
-
1881
+ /* FIXME: skip latches */
1854
1882
for (i = 0 ; i < cell_count; i++) {
1855
1883
/* We release search latches every once in a while to
1856
1884
give other queries a chance to run. */
@@ -1882,7 +1910,7 @@ static bool btr_search_hash_table_validate(THD *thd, ulint hash_table_id)
1882
1910
}
1883
1911
}
1884
1912
1885
- node = static_cast <ahi_node*>(part.table .array [i].node );
1913
+ node = static_cast <ahi_node*>(part.table .array [i].first );
1886
1914
1887
1915
for (; node != NULL ; node = node->next ) {
1888
1916
const buf_block_t * block
0 commit comments