1 | /***************************************************************************** |
2 | |
3 | Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved. |
4 | |
5 | This program is free software; you can redistribute it and/or modify it under |
6 | the terms of the GNU General Public License as published by the Free Software |
7 | Foundation; version 2 of the License. |
8 | |
9 | This program is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
11 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License along with |
14 | this program; if not, write to the Free Software Foundation, Inc., |
15 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
16 | |
17 | *****************************************************************************/ |
18 | |
19 | /******************************************************************//** |
20 | @file include gis0type.h |
21 | R-tree header file |
22 | |
23 | Created 2013/03/27 Jimmy Yang |
24 | ***********************************************************************/ |
25 | |
26 | #ifndef gis0type_h |
27 | #define gis0type_h |
28 | |
29 | #include "univ.i" |
30 | |
31 | #include "buf0buf.h" |
32 | #include "data0type.h" |
33 | #include "data0types.h" |
34 | #include "dict0types.h" |
35 | #include "hash0hash.h" |
36 | #include "mem0mem.h" |
37 | #include "rem0types.h" |
38 | #include "row0types.h" |
39 | #include "trx0types.h" |
40 | #include "ut0vec.h" |
41 | #include "ut0wqueue.h" |
42 | #include "que0types.h" |
43 | #include "gis0geo.h" |
44 | #include "ut0new.h" |
45 | |
46 | #include <vector> |
47 | #include <list> |
48 | |
49 | /* Node Sequence Number. Only updated when page splits */ |
50 | typedef ib_uint32_t node_seq_t; |
51 | |
52 | /* RTree internal non-leaf Nodes to be searched, from root to leaf */ |
53 | typedef struct node_visit { |
54 | ulint page_no; /*!< the page number */ |
55 | node_seq_t seq_no; /*!< the SSN (split sequence number */ |
56 | ulint level; /*!< the page's index level */ |
57 | ulint child_no; /*!< child page num if for parent |
58 | recording */ |
59 | btr_pcur_t* cursor; /*!< cursor structure if we positioned |
60 | FIXME: there is no need to use whole |
61 | btr_pcur_t, just the position related |
62 | members */ |
63 | double mbr_inc; /*!< whether this node needs to be |
64 | enlarged for insertion */ |
65 | } node_visit_t; |
66 | |
67 | typedef std::vector<node_visit_t, ut_allocator<node_visit_t> > rtr_node_path_t; |
68 | |
69 | typedef struct rtr_rec { |
70 | rec_t* r_rec; /*!< matched record */ |
71 | bool locked; /*!< whether the record locked */ |
72 | } rtr_rec_t; |
73 | |
74 | typedef std::vector<rtr_rec_t, ut_allocator<rtr_rec_t> > rtr_rec_vector; |
75 | |
76 | /* Structure for matched records on the leaf page */ |
77 | typedef struct matched_rec { |
78 | byte* bufp; /*!< aligned buffer point */ |
79 | byte rec_buf[UNIV_PAGE_SIZE_MAX * 2]; |
80 | /*!< buffer used to copy matching rec */ |
81 | buf_block_t block; /*!< the shadow buffer block */ |
82 | ulint used; /*!< memory used */ |
83 | rtr_rec_vector* matched_recs; /*!< vector holding the matching rec */ |
84 | ib_mutex_t rtr_match_mutex;/*!< mutex protect the match_recs |
85 | vector */ |
86 | bool valid; /*!< whether result in matched_recs |
87 | or this search is valid (page not |
88 | dropped) */ |
89 | bool locked; /*!< whether these recs locked */ |
90 | } matched_rec_t; |
91 | |
92 | /* In memory representation of a minimum bounding rectangle */ |
93 | typedef struct rtr_mbr { |
94 | double xmin; /*!< minimum on x */ |
95 | double xmax; /*!< maximum on x */ |
96 | double ymin; /*!< minimum on y */ |
97 | double ymax; /*!< maximum on y */ |
98 | } rtr_mbr_t; |
99 | |
100 | /* Maximum index level for R-Tree, this is consistent with BTR_MAX_LEVELS */ |
101 | #define RTR_MAX_LEVELS 100 |
102 | |
103 | /* Number of pages we latch at leaf level when there is possible Tree |
104 | modification (split, shrink), we always latch left, current |
105 | and right pages */ |
106 | #define RTR_LEAF_LATCH_NUM 3 |
107 | |
108 | /** Vectors holding the matching internal pages/nodes and leaf records */ |
109 | typedef struct rtr_info{ |
110 | rtr_node_path_t*path; /*!< vector holding matching pages */ |
111 | rtr_node_path_t*parent_path; |
112 | /*!< vector holding parent pages during |
113 | search */ |
114 | matched_rec_t* matches;/*!< struct holding matching leaf records */ |
115 | ib_mutex_t rtr_path_mutex; |
116 | /*!< mutex protect the "path" vector */ |
117 | buf_block_t* tree_blocks[RTR_MAX_LEVELS + RTR_LEAF_LATCH_NUM]; |
118 | /*!< tracking pages that would be locked |
119 | at leaf level, for future free */ |
120 | ulint tree_savepoints[RTR_MAX_LEVELS + RTR_LEAF_LATCH_NUM]; |
121 | /*!< savepoint used to release latches/blocks |
122 | on each level and leaf level */ |
123 | rtr_mbr_t mbr; /*!< the search MBR */ |
124 | que_thr_t* thr; /*!< the search thread */ |
125 | mem_heap_t* heap; /*!< memory heap */ |
126 | btr_cur_t* cursor; /*!< cursor used for search */ |
127 | dict_index_t* index; /*!< index it is searching */ |
128 | bool need_prdt_lock; |
129 | /*!< whether we will need predicate lock |
130 | the tree */ |
131 | bool need_page_lock; |
132 | /*!< whether we will need predicate page lock |
133 | the tree */ |
134 | bool allocated;/*!< whether this structure is allocate or |
135 | on stack */ |
136 | bool mbr_adj;/*!< whether mbr will need to be enlarged |
137 | for an insertion operation */ |
138 | bool fd_del; /*!< found deleted row */ |
139 | const dtuple_t* search_tuple; |
140 | /*!< search tuple being used */ |
141 | page_cur_mode_t search_mode; |
142 | /*!< current search mode */ |
143 | } rtr_info_t; |
144 | |
145 | typedef std::list<rtr_info_t*, ut_allocator<rtr_info_t*> > rtr_info_active; |
146 | |
147 | /* Tracking structure for all onoging search for an index */ |
148 | typedef struct rtr_info_track { |
149 | rtr_info_active* rtr_active; /*!< Active search info */ |
150 | ib_mutex_t rtr_active_mutex; |
151 | /*!< mutex to protect |
152 | rtr_active */ |
153 | } rtr_info_track_t; |
154 | |
155 | /* Node Sequence Number and mutex protects it. */ |
156 | typedef struct rtree_ssn { |
157 | ib_mutex_t mutex; /*!< mutex protect the seq num */ |
158 | node_seq_t seq_no; /*!< the SSN (node sequence number) */ |
159 | } rtr_ssn_t; |
160 | |
161 | /* This is to record the record movement between pages. Used for corresponding |
162 | lock movement */ |
163 | typedef struct rtr_rec_move { |
164 | rec_t* old_rec; /*!< record being moved in old page */ |
165 | rec_t* new_rec; /*!< new record location */ |
166 | bool moved; /*!< whether lock are moved too */ |
167 | } rtr_rec_move_t; |
168 | #endif /*!< gis0rtree.h */ |
169 | |