Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
4375d827
Commit
4375d827
authored
May 23, 2002
by
ram@gw.udmsearch.izhnet.ru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Heap table code cleanup
parent
d1e13bec
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
77 additions
and
71 deletions
+77
-71
heap/heapdef.h
heap/heapdef.h
+2
-2
heap/hp_hash.c
heap/hp_hash.c
+18
-23
heap/hp_open.c
heap/hp_open.c
+24
-18
heap/hp_rfirst.c
heap/hp_rfirst.c
+2
-1
heap/hp_rkey.c
heap/hp_rkey.c
+24
-24
heap/hp_rlast.c
heap/hp_rlast.c
+2
-1
heap/hp_rnext.c
heap/hp_rnext.c
+2
-1
heap/hp_rprev.c
heap/hp_rprev.c
+2
-1
include/heap.h
include/heap.h
+1
-0
No files found.
heap/heapdef.h
View file @
4375d827
...
...
@@ -82,11 +82,11 @@ extern void hp_make_key(HP_KEYDEF *keydef,byte *key,const byte *rec);
extern
uint
hp_rb_make_key
(
HP_KEYDEF
*
keydef
,
byte
*
key
,
const
byte
*
rec
,
byte
*
recpos
);
extern
uint
hp_rb_key_length
(
HP_KEYDEF
*
keydef
,
const
byte
*
key
);
extern
uint
hp_rb_null_key_length
(
HP_KEYDEF
*
keydef
,
const
byte
*
key
);
extern
my_bool
hp_if_null_in_key
(
HP_KEYDEF
*
keyinfo
,
const
byte
*
record
);
extern
int
hp_close
(
register
HP_INFO
*
info
);
extern
void
hp_clear
(
HP_SHARE
*
info
);
extern
uint
hp_rb_pack_key
(
HP_INFO
*
info
,
uint
inx
,
uchar
*
key
,
const
uchar
*
old
,
uint
k_length
);
extern
uint
hp_rb_pack_key
(
HP_KEYDEF
*
keydef
,
uchar
*
key
,
const
uchar
*
old
);
#ifdef THREAD
extern
pthread_mutex_t
THR_LOCK_heap
;
#else
...
...
heap/hp_hash.c
View file @
4375d827
...
...
@@ -26,16 +26,17 @@ ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, const byte *start_key,
enum
ha_rkey_function
end_search_flag
)
{
ha_rows
start_pos
,
end_pos
;
TREE
*
rb_tree
=
&
info
->
s
->
keydef
[
inx
].
rb_tree
;
HP_KEYDEF
*
keyinfo
=
info
->
s
->
keydef
+
inx
;
TREE
*
rb_tree
=
&
keyinfo
->
rb_tree
;
heap_rb_param
custom_arg
;
info
->
lastinx
=
inx
;
custom_arg
.
keyseg
=
info
->
s
->
keydef
[
inx
].
seg
;
custom_arg
.
keyseg
=
keyinfo
->
seg
;
custom_arg
.
search_flag
=
SEARCH_FIND
|
SEARCH_SAME
;
custom_arg
.
key_length
=
start_key_len
;
if
(
start_key
)
{
hp_rb_pack_key
(
info
,
inx
,
info
->
recbuf
,
start_key
,
start_key_len
);
hp_rb_pack_key
(
keyinfo
,
info
->
recbuf
,
start_key
);
start_pos
=
tree_record_pos
(
rb_tree
,
info
->
recbuf
,
start_search_flag
,
&
custom_arg
);
}
...
...
@@ -47,7 +48,7 @@ ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, const byte *start_key,
custom_arg
.
key_length
=
end_key_len
;
if
(
end_key
)
{
hp_rb_pack_key
(
info
,
inx
,
info
->
recbuf
,
end_key
,
end_key_len
);
hp_rb_pack_key
(
keyinfo
,
info
->
recbuf
,
end_key
);
end_pos
=
tree_record_pos
(
rb_tree
,
info
->
recbuf
,
end_search_flag
,
&
custom_arg
);
}
...
...
@@ -473,12 +474,10 @@ uint hp_rb_make_key(HP_KEYDEF *keydef, byte *key,
return
key
-
start_key
;
}
uint
hp_rb_pack_key
(
HP_INFO
*
info
,
uint
inx
,
uchar
*
key
,
const
uchar
*
old
,
uint
k_length
)
uint
hp_rb_pack_key
(
HP_KEYDEF
*
keydef
,
uchar
*
key
,
const
uchar
*
old
)
{
HA_KEYSEG
*
seg
,
*
endseg
;
uchar
*
start_key
=
key
;
HP_KEYDEF
*
keydef
=
info
->
s
->
keydef
+
inx
;
for
(
seg
=
keydef
->
seg
,
endseg
=
seg
+
keydef
->
keysegs
;
seg
<
endseg
;
old
+=
seg
->
length
,
seg
++
)
...
...
@@ -494,28 +493,24 @@ uint hp_rb_pack_key(HP_INFO *info, uint inx, uchar *key, const uchar *old,
return
key
-
start_key
;
}
uint
hp_rb_key_length
(
HP_KEYDEF
*
keydef
,
const
byte
*
key
)
uint
hp_rb_key_length
(
HP_KEYDEF
*
keydef
,
const
byte
*
key
__attribute__
((
unused
)))
{
return
keydef
->
length
;
}
uint
hp_rb_null_key_length
(
HP_KEYDEF
*
keydef
,
const
byte
*
key
)
{
const
byte
*
start_key
=
key
;
HA_KEYSEG
*
seg
,
*
endseg
;
if
(
keydef
->
flag
&
HA_NULL_PART_KEY
)
{
for
(
seg
=
keydef
->
seg
,
endseg
=
seg
+
keydef
->
keysegs
;
seg
<
endseg
;
seg
++
)
{
if
(
seg
->
null_bit
)
{
if
(
!*
key
++
)
continue
;
}
key
+=
seg
->
length
;
}
return
key
-
start_key
;
}
else
for
(
seg
=
keydef
->
seg
,
endseg
=
seg
+
keydef
->
keysegs
;
seg
<
endseg
;
seg
++
)
{
return
keydef
->
length
;
if
(
seg
->
null_bit
&&
!*
key
++
)
continue
;
key
+=
seg
->
length
;
}
return
key
-
start_key
;
}
/*
...
...
heap/hp_open.c
View file @
4375d827
...
...
@@ -48,30 +48,37 @@ HP_INFO *heap_open(const char *name, int mode, uint keys, HP_KEYDEF *keydef,
pthread_mutex_lock
(
&
THR_LOCK_heap
);
if
(
!
(
share
=
hp_find_named_heap
(
name
)))
{
HP_KEYDEF
*
keyinfo
;
DBUG_PRINT
(
"info"
,(
"Initializing new table"
));
for
(
i
=
key_segs
=
max_length
=
0
;
i
<
keys
;
i
++
)
for
(
i
=
key_segs
=
max_length
=
0
,
keyinfo
=
keydef
;
i
<
keys
;
i
++
,
keyinfo
++
)
{
key_segs
+=
keydef
[
i
].
keysegs
;
if
(
keydef
[
i
].
algorithm
==
HA_KEY_ALG_BTREE
)
key_segs
++
;
bzero
((
char
*
)
&
keydef
[
i
].
block
,
sizeof
(
keydef
[
i
].
block
));
bzero
((
char
*
)
&
keydef
[
i
].
rb_tree
,
sizeof
(
keydef
[
i
].
rb_tree
));
for
(
j
=
length
=
0
;
j
<
keydef
[
i
].
keysegs
;
j
++
)
bzero
((
char
*
)
&
keyinfo
->
block
,
sizeof
(
keyinfo
->
block
));
bzero
((
char
*
)
&
keyinfo
->
rb_tree
,
sizeof
(
keyinfo
->
rb_tree
));
for
(
j
=
length
=
0
;
j
<
keyinfo
->
keysegs
;
j
++
)
{
length
+=
key
def
[
i
].
seg
[
j
].
length
;
if
(
key
def
[
i
].
seg
[
j
].
null_bit
)
length
+=
key
info
->
seg
[
j
].
length
;
if
(
key
info
->
seg
[
j
].
null_bit
)
{
if
(
!
(
key
def
[
i
].
flag
&
HA_NULL_ARE_EQUAL
))
key
def
[
i
].
flag
|=
HA_NULL_PART_KEY
;
if
(
key
def
[
i
].
algorithm
==
HA_KEY_ALG_BTREE
)
key
def
[
i
].
rb_tree
.
size_of_element
++
;
if
(
!
(
key
info
->
flag
&
HA_NULL_ARE_EQUAL
))
key
info
->
flag
|=
HA_NULL_PART_KEY
;
if
(
key
info
->
algorithm
==
HA_KEY_ALG_BTREE
)
key
info
->
rb_tree
.
size_of_element
++
;
}
}
key
def
[
i
].
length
=
length
;
length
+=
key
def
[
i
].
rb_tree
.
size_of_element
+
((
key
def
[
i
].
algorithm
==
HA_KEY_ALG_BTREE
)
?
sizeof
(
byte
*
)
:
0
);
key
info
->
length
=
length
;
length
+=
key
info
->
rb_tree
.
size_of_element
+
((
key
info
->
algorithm
==
HA_KEY_ALG_BTREE
)
?
sizeof
(
byte
*
)
:
0
);
if
(
length
>
max_length
)
max_length
=
length
;
key_segs
+=
keyinfo
->
keysegs
;
if
(
keyinfo
->
algorithm
==
HA_KEY_ALG_BTREE
)
{
key_segs
++
;
/* additional HA_KEYTYPE_END segment */
if
(
keyinfo
->
flag
&
HA_NULL_PART_KEY
)
keyinfo
->
get_key_length
=
hp_rb_null_key_length
;
else
keyinfo
->
get_key_length
=
hp_rb_key_length
;
}
}
if
(
!
(
share
=
(
HP_SHARE
*
)
my_malloc
((
uint
)
sizeof
(
HP_SHARE
)
+
keys
*
sizeof
(
HP_KEYDEF
)
+
...
...
@@ -86,9 +93,8 @@ HP_INFO *heap_open(const char *name, int mode, uint keys, HP_KEYDEF *keydef,
init_block
(
&
share
->
block
,
reclength
+
1
,
min_records
,
max_records
);
/* Fix keys */
memcpy
(
share
->
keydef
,
keydef
,
(
size_t
)
(
sizeof
(
keydef
[
0
])
*
keys
));
for
(
i
=
0
;
i
<
keys
;
i
++
)
for
(
i
=
0
,
keyinfo
=
share
->
keydef
;
i
<
keys
;
i
++
,
keyinfo
++
)
{
HP_KEYDEF
*
keyinfo
=
share
->
keydef
+
i
;
uint
nsegs
=
keydef
[
i
].
keysegs
;
if
(
keydef
[
i
].
algorithm
==
HA_KEY_ALG_BTREE
)
...
...
heap/hp_rfirst.c
View file @
4375d827
...
...
@@ -31,7 +31,8 @@ int heap_rfirst(HP_INFO *info, byte *record, int inx)
if
((
pos
=
tree_search_edge
(
&
keyinfo
->
rb_tree
,
info
->
parents
,
&
info
->
last_pos
,
offsetof
(
TREE_ELEMENT
,
left
))))
{
memcpy
(
&
pos
,
pos
+
hp_rb_key_length
(
keyinfo
,
pos
),
sizeof
(
byte
*
));
memcpy
(
&
pos
,
pos
+
(
*
keyinfo
->
get_key_length
)(
keyinfo
,
pos
),
sizeof
(
byte
*
));
info
->
current_ptr
=
pos
;
memcpy
(
record
,
pos
,
(
size_t
)
share
->
reclength
);
info
->
update
=
HA_STATE_AKTIV
;
...
...
heap/hp_rkey.c
View file @
4375d827
...
...
@@ -20,56 +20,56 @@ int heap_rkey(HP_INFO *info, byte *record, int inx, const byte *key,
uint
key_len
,
enum
ha_rkey_function
find_flag
)
{
byte
*
pos
;
HP_SHARE
*
share
=
info
->
s
;
HP_KEYDEF
*
keyinfo
=
share
->
keydef
+
inx
;
HP_SHARE
*
share
=
info
->
s
;
HP_KEYDEF
*
keyinfo
=
share
->
keydef
+
inx
;
DBUG_ENTER
(
"heap_rkey"
);
DBUG_PRINT
(
"enter"
,(
"base: %lx inx: %d"
,
info
,
inx
));
if
((
uint
)
inx
>=
share
->
keys
)
{
DBUG_RETURN
(
my_errno
=
HA_ERR_WRONG_INDEX
);
DBUG_RETURN
(
my_errno
=
HA_ERR_WRONG_INDEX
);
}
info
->
lastinx
=
inx
;
info
->
current_record
=
(
ulong
)
~
0L
;
/* For heap_rrnd() */
info
->
lastinx
=
inx
;
info
->
current_record
=
(
ulong
)
~
0L
;
/* For heap_rrnd() */
if
(
keyinfo
->
algorithm
==
HA_KEY_ALG_BTREE
)
{
heap_rb_param
custom_arg
;
hp_rb_pack_key
(
info
,
inx
,
info
->
recbuf
,
key
,
key_len
);
hp_rb_pack_key
(
keyinfo
,
info
->
recbuf
,
key
);
custom_arg
.
keyseg
=
info
->
s
->
keydef
[
inx
].
seg
;
custom_arg
.
key_length
=
key_len
;
custom_arg
.
search_flag
=
SEARCH_FIND
|
SEARCH_SAME
;
custom_arg
.
keyseg
=
info
->
s
->
keydef
[
inx
].
seg
;
custom_arg
.
key_length
=
key_len
;
custom_arg
.
search_flag
=
SEARCH_FIND
|
SEARCH_SAME
;
/* for next rkey() after deletion */
if
(
find_flag
==
HA_READ_AFTER_KEY
)
info
->
last_find_flag
=
HA_READ_KEY_OR_NEXT
;
info
->
last_find_flag
=
HA_READ_KEY_OR_NEXT
;
else
if
(
find_flag
==
HA_READ_BEFORE_KEY
)
info
->
last_find_flag
=
HA_READ_KEY_OR_PREV
;
info
->
last_find_flag
=
HA_READ_KEY_OR_PREV
;
else
info
->
last_find_flag
=
find_flag
;
info
->
lastkey_len
=
key_len
;
if
(
!
(
pos
=
tree_search_key
(
&
keyinfo
->
rb_tree
,
info
->
recbuf
,
info
->
parents
,
&
info
->
last_pos
,
find_flag
,
&
custom_arg
)))
info
->
last_find_flag
=
find_flag
;
info
->
lastkey_len
=
key_len
;
if
(
!
(
pos
=
tree_search_key
(
&
keyinfo
->
rb_tree
,
info
->
recbuf
,
info
->
parents
,
&
info
->
last_pos
,
find_flag
,
&
custom_arg
)))
{
info
->
update
=
0
;
DBUG_RETURN
(
my_errno
=
HA_ERR_KEY_NOT_FOUND
);
info
->
update
=
0
;
DBUG_RETURN
(
my_errno
=
HA_ERR_KEY_NOT_FOUND
);
}
memcpy
(
&
pos
,
pos
+
hp_rb_key_length
(
keyinfo
,
pos
),
sizeof
(
byte
*
));
info
->
current_ptr
=
pos
;
memcpy
(
&
pos
,
pos
+
(
*
keyinfo
->
get_key_length
)
(
keyinfo
,
pos
),
sizeof
(
byte
*
));
info
->
current_ptr
=
pos
;
}
else
{
if
(
!
(
pos
=
hp_search
(
info
,
share
->
keydef
+
inx
,
key
,
0
)))
if
(
!
(
pos
=
hp_search
(
info
,
share
->
keydef
+
inx
,
key
,
0
)))
{
info
->
update
=
0
;
info
->
update
=
0
;
DBUG_RETURN
(
my_errno
);
}
if
(
!
(
keyinfo
->
flag
&
HA_NOSAME
))
memcpy
(
info
->
lastkey
,
key
,
(
size_t
)
keyinfo
->
length
);
memcpy
(
info
->
lastkey
,
key
,
(
size_t
)
keyinfo
->
length
);
}
memcpy
(
record
,
pos
,
(
size_t
)
share
->
reclength
);
info
->
update
=
HA_STATE_AKTIV
;
memcpy
(
record
,
pos
,
(
size_t
)
share
->
reclength
);
info
->
update
=
HA_STATE_AKTIV
;
DBUG_RETURN
(
0
);
}
...
...
heap/hp_rlast.c
View file @
4375d827
...
...
@@ -32,7 +32,8 @@ int heap_rlast(HP_INFO *info, byte *record, int inx)
if
((
pos
=
tree_search_edge
(
&
keyinfo
->
rb_tree
,
info
->
parents
,
&
info
->
last_pos
,
offsetof
(
TREE_ELEMENT
,
right
))))
{
memcpy
(
&
pos
,
pos
+
hp_rb_key_length
(
keyinfo
,
pos
),
sizeof
(
byte
*
));
memcpy
(
&
pos
,
pos
+
(
*
keyinfo
->
get_key_length
)(
keyinfo
,
pos
),
sizeof
(
byte
*
));
info
->
current_ptr
=
pos
;
memcpy
(
record
,
pos
,
(
size_t
)
share
->
reclength
);
info
->
update
=
HA_STATE_AKTIV
;
...
...
heap/hp_rnext.c
View file @
4375d827
...
...
@@ -47,7 +47,8 @@ int heap_rnext(HP_INFO *info, byte *record)
}
if
(
pos
)
{
memcpy
(
&
pos
,
pos
+
hp_rb_key_length
(
keyinfo
,
pos
),
sizeof
(
byte
*
));
memcpy
(
&
pos
,
pos
+
(
*
keyinfo
->
get_key_length
)(
keyinfo
,
pos
),
sizeof
(
byte
*
));
info
->
current_ptr
=
pos
;
}
else
...
...
heap/hp_rprev.c
View file @
4375d827
...
...
@@ -47,7 +47,8 @@ int heap_rprev(HP_INFO *info, byte *record)
}
if
(
pos
)
{
memcpy
(
&
pos
,
pos
+
hp_rb_key_length
(
keyinfo
,
pos
),
sizeof
(
byte
*
));
memcpy
(
&
pos
,
pos
+
(
*
keyinfo
->
get_key_length
)(
keyinfo
,
pos
),
sizeof
(
byte
*
));
info
->
current_ptr
=
pos
;
}
else
...
...
include/heap.h
View file @
4375d827
...
...
@@ -91,6 +91,7 @@ typedef struct st_hp_keydef /* Key definition with open */
const
byte
*
record
,
byte
*
recpos
);
int
(
*
delete_key
)(
struct
st_heap_info
*
info
,
struct
st_hp_keydef
*
keyinfo
,
const
byte
*
record
,
byte
*
recpos
,
int
flag
);
uint
(
*
get_key_length
)(
struct
st_hp_keydef
*
keydef
,
const
byte
*
key
);
}
HP_KEYDEF
;
typedef
struct
st_heap_share
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment