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
2212b9d8
Commit
2212b9d8
authored
Oct 30, 2006
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an extra block to avoid that DBUG_ENTER declare variables after code
parent
3ca26c2e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
132 additions
and
126 deletions
+132
-126
myisam/sort.c
myisam/sort.c
+132
-126
No files found.
myisam/sort.c
View file @
2212b9d8
...
...
@@ -322,159 +322,165 @@ pthread_handler_t thr_find_all_keys(void *arg)
if
(
my_thread_init
())
goto
err
;
DBUG_ENTER
(
"thr_find_all_keys"
);
DBUG_PRINT
(
"enter"
,
(
"master: %d"
,
sort_param
->
master
));
if
(
sort_param
->
sort_info
->
got_error
)
goto
err
;
if
(
sort_param
->
keyinfo
->
flag
&
HA_VAR_LENGTH_KEY
)
{
sort_param
->
write_keys
=
write_keys_varlen
;
sort_param
->
read_to_buffer
=
read_to_buffer_varlen
;
sort_param
->
write_key
=
write_merge_key_varlen
;
}
else
{
sort_param
->
write_keys
=
write_keys
;
sort_param
->
read_to_buffer
=
read_to_buffer
;
sort_param
->
write_key
=
write_merge_key
;
}
my_b_clear
(
&
sort_param
->
tempfile
);
my_b_clear
(
&
sort_param
->
tempfile_for_exceptions
);
bzero
((
char
*
)
&
sort_param
->
buffpek
,
sizeof
(
sort_param
->
buffpek
));
bzero
((
char
*
)
&
sort_param
->
unique
,
sizeof
(
sort_param
->
unique
));
sort_keys
=
(
uchar
**
)
NULL
;
memavl
=
max
(
sort_param
->
sortbuff_size
,
MIN_SORT_MEMORY
);
idx
=
sort_param
->
sort_info
->
max_records
;
sort_length
=
sort_param
->
key_length
;
maxbuffer
=
1
;
{
/* Add extra block since DBUG_ENTER declare variables */
DBUG_ENTER
(
"thr_find_all_keys"
);
DBUG_PRINT
(
"enter"
,
(
"master: %d"
,
sort_param
->
master
));
if
(
sort_param
->
sort_info
->
got_error
)
goto
err
;
while
(
memavl
>=
MIN_SORT_MEMORY
)
{
if
((
my_off_t
)
(
idx
+
1
)
*
(
sort_length
+
sizeof
(
char
*
))
<=
(
my_off_t
)
memavl
)
keys
=
idx
+
1
;
if
(
sort_param
->
keyinfo
->
flag
&
HA_VAR_LENGTH_KEY
)
{
sort_param
->
write_keys
=
write_keys_varlen
;
sort_param
->
read_to_buffer
=
read_to_buffer_varlen
;
sort_param
->
write_key
=
write_merge_key_varlen
;
}
else
{
uint
skr
;
do
sort_param
->
write_keys
=
write_keys
;
sort_param
->
read_to_buffer
=
read_to_buffer
;
sort_param
->
write_key
=
write_merge_key
;
}
my_b_clear
(
&
sort_param
->
tempfile
);
my_b_clear
(
&
sort_param
->
tempfile_for_exceptions
);
bzero
((
char
*
)
&
sort_param
->
buffpek
,
sizeof
(
sort_param
->
buffpek
));
bzero
((
char
*
)
&
sort_param
->
unique
,
sizeof
(
sort_param
->
unique
));
sort_keys
=
(
uchar
**
)
NULL
;
memavl
=
max
(
sort_param
->
sortbuff_size
,
MIN_SORT_MEMORY
);
idx
=
sort_param
->
sort_info
->
max_records
;
sort_length
=
sort_param
->
key_length
;
maxbuffer
=
1
;
while
(
memavl
>=
MIN_SORT_MEMORY
)
{
if
((
my_off_t
)
(
idx
+
1
)
*
(
sort_length
+
sizeof
(
char
*
))
<=
(
my_off_t
)
memavl
)
keys
=
idx
+
1
;
else
{
skr
=
maxbuffer
;
if
(
memavl
<
sizeof
(
BUFFPEK
)
*
maxbuffer
||
(
keys
=
(
memavl
-
sizeof
(
BUFFPEK
)
*
maxbuffer
)
/
(
sort_length
+
sizeof
(
char
*
)))
<=
1
||
keys
<
(
uint
)
maxbuffer
)
uint
skr
;
do
{
mi_check_print_error
(
sort_param
->
sort_info
->
param
,
"sort_buffer_size is to small"
);
goto
err
;
skr
=
maxbuffer
;
if
(
memavl
<
sizeof
(
BUFFPEK
)
*
maxbuffer
||
(
keys
=
(
memavl
-
sizeof
(
BUFFPEK
)
*
maxbuffer
)
/
(
sort_length
+
sizeof
(
char
*
)))
<=
1
||
keys
<
(
uint
)
maxbuffer
)
{
mi_check_print_error
(
sort_param
->
sort_info
->
param
,
"sort_buffer_size is to small"
);
goto
err
;
}
}
while
((
maxbuffer
=
(
int
)
(
idx
/
(
keys
-
1
)
+
1
))
!=
skr
);
}
while
((
maxbuffer
=
(
int
)
(
idx
/
(
keys
-
1
)
+
1
))
!=
skr
);
}
if
((
sort_keys
=
(
uchar
**
)
my_malloc
(
keys
*
(
sort_length
+
sizeof
(
char
*
))
+
((
sort_param
->
keyinfo
->
flag
&
HA_FULLTEXT
)
?
HA_FT_MAXBYTELEN
:
0
),
MYF
(
0
))))
{
if
(
my_init_dynamic_array
(
&
sort_param
->
buffpek
,
sizeof
(
BUFFPEK
),
maxbuffer
,
maxbuffer
/
2
))
if
((
sort_keys
=
(
uchar
**
)
my_malloc
(
keys
*
(
sort_length
+
sizeof
(
char
*
))
+
((
sort_param
->
keyinfo
->
flag
&
HA_FULLTEXT
)
?
HA_FT_MAXBYTELEN
:
0
),
MYF
(
0
))))
{
my_free
((
gptr
)
sort_keys
,
MYF
(
0
));
sort_keys
=
(
uchar
**
)
NULL
;
/* for err: label */
if
(
my_init_dynamic_array
(
&
sort_param
->
buffpek
,
sizeof
(
BUFFPEK
),
maxbuffer
,
maxbuffer
/
2
))
{
my_free
((
gptr
)
sort_keys
,
MYF
(
0
));
sort_keys
=
(
uchar
**
)
NULL
;
/* for err: label */
}
else
break
;
}
else
break
;
old_memavl
=
memavl
;
if
((
memavl
=
memavl
/
4
*
3
)
<
MIN_SORT_MEMORY
&&
old_memavl
>
MIN_SORT_MEMORY
)
memavl
=
MIN_SORT_MEMORY
;
}
if
(
memavl
<
MIN_SORT_MEMORY
)
{
mi_check_print_error
(
sort_param
->
sort_info
->
param
,
"Sort buffer too small"
);
goto
err
;
/* purecov: tested */
}
old_memavl
=
memavl
;
if
((
memavl
=
memavl
/
4
*
3
)
<
MIN_SORT_MEMORY
&&
old_memavl
>
MIN_SORT_MEMORY
)
memavl
=
MIN_SORT_MEMORY
;
}
if
(
memavl
<
MIN_SORT_MEMORY
)
{
mi_check_print_error
(
sort_param
->
sort_info
->
param
,
"Sort buffer too small"
);
goto
err
;
/* purecov: tested */
}
if
(
sort_param
->
sort_info
->
param
->
testflag
&
T_VERBOSE
)
printf
(
"Key %d - Allocating buffer for %d keys
\n
"
,
sort_param
->
key
+
1
,
keys
);
sort_param
->
sort_keys
=
sort_keys
;
if
(
sort_param
->
sort_info
->
param
->
testflag
&
T_VERBOSE
)
printf
(
"Key %d - Allocating buffer for %d keys
\n
"
,
sort_param
->
key
+
1
,
keys
);
sort_param
->
sort_keys
=
sort_keys
;
idx
=
error
=
0
;
sort_keys
[
0
]
=
(
uchar
*
)
(
sort_keys
+
keys
);
idx
=
error
=
0
;
sort_keys
[
0
]
=
(
uchar
*
)
(
sort_keys
+
keys
);
DBUG_PRINT
(
"info"
,
(
"reading keys"
));
while
(
!
(
error
=
sort_param
->
sort_info
->
got_error
)
&&
!
(
error
=
(
*
sort_param
->
key_read
)(
sort_param
,
sort_keys
[
idx
])))
{
if
(
sort_param
->
real_key_length
>
sort_param
->
key_length
)
DBUG_PRINT
(
"info"
,
(
"reading keys"
));
while
(
!
(
error
=
sort_param
->
sort_info
->
got_error
)
&&
!
(
error
=
(
*
sort_param
->
key_read
)(
sort_param
,
sort_keys
[
idx
])))
{
if
(
write_key
(
sort_param
,
sort_keys
[
idx
],
&
sort_param
->
tempfile_for_exceptions
))
goto
err
;
continue
;
}
if
(
sort_param
->
real_key_length
>
sort_param
->
key_length
)
{
if
(
write_key
(
sort_param
,
sort_keys
[
idx
],
&
sort_param
->
tempfile_for_exceptions
))
goto
err
;
continue
;
}
if
(
++
idx
==
keys
)
if
(
++
idx
==
keys
)
{
if
(
sort_param
->
write_keys
(
sort_param
,
sort_keys
,
idx
-
1
,
(
BUFFPEK
*
)
alloc_dynamic
(
&
sort_param
->
buffpek
),
&
sort_param
->
tempfile
))
goto
err
;
sort_keys
[
0
]
=
(
uchar
*
)
(
sort_keys
+
keys
);
memcpy
(
sort_keys
[
0
],
sort_keys
[
idx
-
1
],
(
size_t
)
sort_param
->
key_length
);
idx
=
1
;
}
sort_keys
[
idx
]
=
sort_keys
[
idx
-
1
]
+
sort_param
->
key_length
;
}
if
(
error
>
0
)
goto
err
;
if
(
sort_param
->
buffpek
.
elements
)
{
if
(
sort_param
->
write_keys
(
sort_param
,
sort_keys
,
idx
-
1
,
if
(
sort_param
->
write_keys
(
sort_param
,
sort_keys
,
idx
,
(
BUFFPEK
*
)
alloc_dynamic
(
&
sort_param
->
buffpek
),
&
sort_param
->
tempfile
))
goto
err
;
sort_keys
[
0
]
=
(
uchar
*
)
(
sort_keys
+
keys
);
memcpy
(
sort_keys
[
0
],
sort_keys
[
idx
-
1
],
(
size_t
)
sort_param
->
key_length
);
idx
=
1
;
sort_param
->
keys
=
(
sort_param
->
buffpek
.
elements
-
1
)
*
(
keys
-
1
)
+
idx
;
}
sort_keys
[
idx
]
=
sort_keys
[
idx
-
1
]
+
sort_param
->
key_length
;
}
if
(
error
>
0
)
goto
err
;
if
(
sort_param
->
buffpek
.
elements
)
{
if
(
sort_param
->
write_keys
(
sort_param
,
sort_keys
,
idx
,
(
BUFFPEK
*
)
alloc_dynamic
(
&
sort_param
->
buffpek
),
&
sort_param
->
tempfile
))
goto
err
;
sort_param
->
keys
=
(
sort_param
->
buffpek
.
elements
-
1
)
*
(
keys
-
1
)
+
idx
;
}
else
sort_param
->
keys
=
idx
;
else
sort_param
->
keys
=
idx
;
sort_param
->
sort_keys_length
=
keys
;
goto
ok
;
sort_param
->
sort_keys_length
=
keys
;
goto
ok
;
err:
DBUG_PRINT
(
"error"
,
(
"got some error"
));
sort_param
->
sort_info
->
got_error
=
1
;
/* no need to protect with a mutex */
if
(
sort_keys
)
my_free
((
gptr
)
sort_keys
,
MYF
(
0
));
sort_param
->
sort_keys
=
0
;
delete_dynamic
(
&
sort_param
->
buffpek
);
close_cached_file
(
&
sort_param
->
tempfile
);
close_cached_file
(
&
sort_param
->
tempfile_for_exceptions
);
DBUG_PRINT
(
"error"
,
(
"got some error"
));
sort_param
->
sort_info
->
got_error
=
1
;
/* no need to protect with a mutex */
if
(
sort_keys
)
my_free
((
gptr
)
sort_keys
,
MYF
(
0
));
sort_param
->
sort_keys
=
0
;
delete_dynamic
(
&
sort_param
->
buffpek
);
close_cached_file
(
&
sort_param
->
tempfile
);
close_cached_file
(
&
sort_param
->
tempfile_for_exceptions
);
ok:
/*
Detach from the share if the writer is involved. Avoid others to
be blocked. This includes a flush of the write buffer. This will
also indicate EOF to the readers.
*/
if
(
sort_param
->
sort_info
->
info
->
rec_cache
.
share
)
remove_io_thread
(
&
sort_param
->
sort_info
->
info
->
rec_cache
);
/* Readers detach from the share if any. Avoid others to be blocked. */
if
(
sort_param
->
read_cache
.
share
)
remove_io_thread
(
&
sort_param
->
read_cache
);
pthread_mutex_lock
(
&
sort_param
->
sort_info
->
mutex
);
if
(
!--
sort_param
->
sort_info
->
threads_running
)
pthread_cond_signal
(
&
sort_param
->
sort_info
->
cond
);
pthread_mutex_unlock
(
&
sort_param
->
sort_info
->
mutex
);
DBUG_PRINT
(
"exit"
,
(
"======== ending thread ========"
));
/*
Detach from the share if the writer is involved. Avoid others to
be blocked. This includes a flush of the write buffer. This will
also indicate EOF to the readers.
*/
if
(
sort_param
->
sort_info
->
info
->
rec_cache
.
share
)
remove_io_thread
(
&
sort_param
->
sort_info
->
info
->
rec_cache
);
/* Readers detach from the share if any. Avoid others to be blocked. */
if
(
sort_param
->
read_cache
.
share
)
remove_io_thread
(
&
sort_param
->
read_cache
);
pthread_mutex_lock
(
&
sort_param
->
sort_info
->
mutex
);
if
(
!--
sort_param
->
sort_info
->
threads_running
)
pthread_cond_signal
(
&
sort_param
->
sort_info
->
cond
);
pthread_mutex_unlock
(
&
sort_param
->
sort_info
->
mutex
);
DBUG_PRINT
(
"exit"
,
(
"======== ending thread ========"
));
}
my_thread_end
();
return
NULL
;
}
...
...
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