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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
4aec929c
Commit
4aec929c
authored
Sep 07, 2000
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Major rewriting in internals.texi.
Docs/internals.texi: Rewrite from pseudo-texi to real texi. :)
parent
403c2d9f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
193 additions
and
104 deletions
+193
-104
Docs/internals.texi
Docs/internals.texi
+193
-104
No files found.
Docs/internals.texi
View file @
4aec929c
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
@set
_
body
_
tags BGCOLOR=#FFFFFF TEXT=#000000 LINK=#101090 VLINK=#7030B0
@set
_
body
_
tags BGCOLOR=#FFFFFF TEXT=#000000 LINK=#101090 VLINK=#7030B0
@settitle @strong
{
MySQL
}
internals Manual for version @value
{
mysql
_
version
}
.
@settitle @strong
{
MySQL
}
internals Manual for version @value
{
mysql
_
version
}
.
@setchapternewpage off
@setchapternewpage off
@paragraphindent 0
@c
%**end of header
@c
%**end of header
@ifinfo
@ifinfo
...
@@ -32,7 +33,7 @@ END-INFO-DIR-ENTRY
...
@@ -32,7 +33,7 @@ END-INFO-DIR-ENTRY
@titlepage
@titlepage
@sp 10
@sp 10
@center @titlefont
{
@strong
{
MySQL
}
Internals Manual
.
}
@center @titlefont
{
@strong
{
MySQL
}
Internals Manual
}
@sp 10
@sp 10
@center Copyright @copyright
{}
1998 TcX AB, Detron HB and Monty Program KB
@center Copyright @copyright
{}
1998 TcX AB, Detron HB and Monty Program KB
@end titlepage
@end titlepage
...
@@ -49,30 +50,33 @@ This is a manual about @strong{MySQL} internals.
...
@@ -49,30 +50,33 @@ This is a manual about @strong{MySQL} internals.
@node caching
@node caching
@chapter How MySQL handles caching
@chapter How MySQL handles caching
MySQL
has the following caches:
@strong
{
MySQL
}
has the following caches:
(Note that the some of the filename have a wrong spelling of cache. :)
(Note that the some of the filename have a wrong spelling of cache. :)
@itemize @bullet
@itemize @bullet
@item Key cache
@item Key cache
A shared cache for all B-tree index blocks in the different NISAM
A shared cache for all B-tree index blocks in the different NISAM
files. Uses hashing and reverse linked lists for quick caching of the
files. Uses hashing and reverse linked lists for quick caching of the
last used blocks and quick flushing of changed entries for a specific
last used blocks and quick flushing of changed entries for a specific
table.
mysys/mf
_
keycash.c
table.
(@file
{
mysys/mf
_
keycash.c
}
)
@item Record cache
@item Record cache
This is used for quick scanning of all records in a table.
This is used for quick scanning of all records in a table.
mysys/mf
_
iocash.c and isam/
_
cash.c
(@file
{
mysys/mf
_
iocash.c
}
and @file
{
isam/
_
cash.c
}
)
@item Table cache
@item Table cache
This holds the last used tables.
sql/sql
_
base.cc
This holds the last used tables.
(@file
{
sql/sql
_
base.cc
}
)
@item Hostname cache
@item Hostname cache
For quick lookup (with reverse name resolving). Is a must when one has a
For quick lookup (with reverse name resolving). Is a must when one has a
slow DNS. sql/hostname.cc
slow DNS.
(@file
{
sql/hostname.cc
}
)
@item Privilege cache
@item Privilege cache
To allow quick change between databases the last used privileges are
To allow quick change between databases the last used privileges are
cached for each user/database combination. sql/sql
_
acl.cc
cached for each user/database combination.
(@file
{
sql/sql
_
acl.cc
}
)
@item Heap table cache
@item Heap table cache
Many use of GROUP BY or DISTINCT caches all found
Many use of GROUP BY or DISTINCT caches all found
...
@@ -89,123 +93,208 @@ join caches in the worst case.
...
@@ -89,123 +93,208 @@ join caches in the worst case.
@chapter How MySQL handles flush tables
@chapter How MySQL handles flush tables
@itemize @bullet
@itemize @bullet
@item
Flush tables is handled in @code
{
sql/sql
_
base.cc::close
_
cached
_
tables()
}
.
@item
@item
Flush tables is handled in sql/sql
_
base.cc::close
_
cached
_
tables().
@Item
The idea of flush tables is to force all tables to be closed. This
The idea of flush tables is to force all tables to be closed. This
is mainly to ensure that if someone adds a new table outside of
is mainly to ensure that if someone adds a new table outside of
MySQL (for example with 'cp') all threads will start using the new table.
@strong
{
MySQL
}
(for example with @code
{
cp
}
) all threads will start using
This will also ensure that all table changes are flushed to disk
the new table. This will also ensure that all table changes are flushed
(but of course not as optimally as simple calling a sync on all tables)!
to disk (but of course not as optimally as simple calling a sync on
all tables)!
@item
@item
When one does a
'flush tables', the variable 'refresh
_
version' will
When one does a
@code
{
FLUSH TABLES
}
, the variable @code
{
refresh
_
version
}
be incremented. Every time a thread releases a table it checks if
will
be incremented. Every time a thread releases a table it checks if
the refresh version of the table (updated at open) is the same as
the refresh version of the table (updated at open) is the same as
the current refresh
_
version. If not it will close it and broadcast
the current refresh
_
version. If not it will close it and broadcast
a signal on COND
_
refresh (to wait any thread that is waiting for
a signal on COND
_
refresh (to wait any thread that is waiting for
all instanses of a table to be closed).
all instanses of a table to be closed).
@item
@item
The current refresh
_
version is also compared to the open refresh
_
version
The current @code
{
refresh
_
version
}
is also compared to the open
after a thread gets a lock on a table. If the refresh version is
@code
{
refresh
_
version
}
after a thread gets a lock on a table. If the
different the thread will free all locks, reopen the table and try
refresh version is different the thread will free all locks, reopen the
to get the locks again; This is just to quickly get all tables to
table and try to get the locks again; This is just to quickly get all
use the newest version. This is handled by
tables to use the newest version. This is handled by
sql/lock.cc::mysql
_
lock
_
tables() and sql/sql
_
base.cc::wait
_
for
_
tables().
@code
{
sql/lock.cc::mysql
_
lock
_
tables()
}
and
@code
{
sql/sql
_
base.cc::wait
_
for
_
tables()
}
.
@item
@item
When all tables has been closed flush-tables will return an ok to client.
When all tables has been closed @code
{
FLUSH TABLES
}
will return an ok
to client.
@item
@item
If the thread that is doing
flush-table
has a lock on some tables,
If the thread that is doing
@code
{
FLUSH TABLES
}
has a lock on some tables,
it will first close
s the locked tables,
wait until all other threads
it will first close
the locked tables, then
wait until all other threads
have also closed the
se and then reopen these
and get the locks.
have also closed the
m, and then reopen them
and get the locks.
After this it will give other threads a
possibility to open the
After this it will give other threads a
chance to open the same tables.
same tables.
@end itemize
@end itemize
@node Filesort
@node Filesort
@chapter How MySQL does sorting (filesort)
@chapter How MySQL does sorting (filesort)
- Read all rows according to key or by table-scanning.
@itemize @bullet
- Store the sort-key in a buffer (sort
_
buffer).
- When the buffer gets full, run a qsort on it and store the result
@item
in a temporary file. Save a pointer to the sorted block.
Read all rows according to key or by table scanning.
- Repeat the above until all rows have been read.
@item
- Repeat the following until there is less than MERGEBUFF2 (15) blocks left.
Store the sort-key in a buffer (@code
{
sort
_
buffer
}
).
- Do a multi-merge of up to MERGEBUFF (7) regions to one block in
another temporary file. Repeat until all blocks from the first file
@item
are in the second file.
When the buffer gets full, run a qsort on it and store the result
- On the last multi-merge, only the pointer to the row (last part of
in a temporary file. Save a pointer to the sorted block.
the sort-key) is written to a result file.
@item
- Now the code in sql/records.cc will be used to read through them
Repeat the above until all rows have been read.
in sorted order by using the row pointers in the result file.
To optimize this, we read in a big block of row pointers, sort these
@item
and then we read the rows in the sorted order into a row buffer
Repeat the following until there is less than @code
{
MERGEBUFF2
}
(15)
(record
_
buffer) .
blocks left.
@item
Do a multi-merge of up to @code
{
MERGEBUFF
}
(7) regions to one block in
another temporary file. Repeat until all blocks from the first file
are in the second file.
@item
On the last multi-merge, only the pointer to the row (last part of
the sort-key) is written to a result file.
@item
Now the code in @file
{
sql/records.cc
}
will be used to read through them
in sorted order by using the row pointers in the result file.
To optimize this, we read in a big block of row pointers, sort these
and then we read the rows in the sorted order into a row buffer
(@code
{
record
_
buffer
}
) .
@end itemize
@node Coding guidelines
@node Coding guidelines
@chapter Coding guidelines
@chapter Coding guidelines
- We are using bitkeeper (www.bitkeeper.com) for source management.
@itemize @bullet
- You should use the MySQL 3.23 or MySQL 4.0 source for all developments.
- If you have any questions about the MySQL source, you can post these
@item
to developers@mysql.com and we will answer them.
We are using @uref
{
http://www.bitkeeper.com/, BitKeeper
}
for source management.
Note that we will shortly change the name of this list to
internals@mysql.com, to more accurately reflect what should be
@item
posted to this list.
You should use the @strong
{
MySQL
}
3.23 or 4.0 source for all developments.
- Try to write code in a lot of black boxes that can be reused or at
@item
least have a clean interface
If you have any questions about the @strong
{
MySQL
}
source, you can post these
- Reuse code; There is already in MySQL a lot of algorithms for list handling,
to @email
{
developers@@mysql.com
}
and we will answer them.
queues, dynamic and hashed arrays, sorting...) that can be reused.
Note that we will shortly change the name of this list to
- Try to always write optimized code, so that you don't have to
@email
{
internals@@mysql.com
}
, to more accurately reflect what should be
go back and rewrite it a couple of months later. It's better to
posted to this list.
spend 3 times as much time designing and writing and optimal function than
having to do it all over again later on.
@item
- Avoid CPU wasteful code, even where it does not matter, so that
Try to write code in a lot of black boxes that can be reused or at
you will not develop sloppy coding habits.
least have a clean interface.
- If you can write it in fewer lines, do it (as long as the code will not
be slower or much harder to read)
@item
- do not check the same pointer for NULL more than once.
Reuse code; There is already a lot of algorithms in MySQL for list handling,
- Use long function and variable names in English; This makes your
queues, dynamic and hashed arrays, sorting, etc. that can be reused.
code easier to read.
- Think assembly - make it easier for the compiler to optimize your code.
@item
- Comment your code when you do something that someone else may think
Try to always write optimized code, so that you don't have to
is 'not trivial'.
go back and rewrite it a couple of months later. It's better to
- Use the my
_
functions like my
_
read/my
_
write/my
_
malloc() that you can
spend 3 times as much time designing and writing an optimal function than
find in the mysys library instead of the direct system calls; This
having to do it all over again later on.
will make your code easier to debug and more portable.
- use libstring functions instead of standard libc string functions
@item
whenever possible
Avoid CPU wasteful code, even where it does not matter, so that
- Avoid using alloc (its REAL slow); For memory allocations that only
you will not develop sloppy coding habits.
needs to live for the lifetime of one thread, on should use
sql
_
alloc() instead.
@item
- Before doing big design decision, please first post a summary of
If you can write it in fewer lines, do it (as long as the code will not
what you want to do, why you want to do it and how you plan to do
be slower or much harder to read).
it. This way we can easily provide you with feedback and also
easily discuss is throughly if some other developer thinks there is better
@item
way to do the same thing!
Do not check the same pointer for @code
{
NULL
}
more than once.
- Use my
_
var as opposed to myVar or MyVar (
_
rather than dancing SHIFT
@item
to spearate words in identifiers)
Use long function and variable names in English; This makes your
- class names start with a capital
code easier to read.
- structure types are typedefed to all caps identifier
- #defines are capitalized
@item
- matching
{
are in the same column
Think assembly - make it easier for the compiler to optimize your code.
- functions return 0 on success , non-zero on error, so you can do
if(a() || b() || c())
{
error("something went wrong");
}
@item
- goto is ok if not abused
Comment your code when you do something that someone else may think
- avoid default variable initalizations, use LINT
_
INIT() if the
is not ''trivial''.
compiler complains after making sure that there is really no way
the variable can be used uninitialized
@item
- Do not instantiate a class if you do not have to
Use the @code
{
my
_
*
}
functions like @code
{
my
_
read()
}
/@code
{
my
_
write()
}
/
- Use pointers rather than array indexing when operating on strings
@code
{
my
_
malloc()
}
that you can find in the @code
{
mysys
}
library instead
of the direct system calls; This will make your code easier to debug and
more portable.
@node Index
@unnumbered Index
@item
Use @code
{
libstring
}
functions instead of standard libc string functions
@printindex fn
whenever possible.
@item
Avoid using @code
{
malloc()
}
(its REAL slow); For memory allocations
that only need to live for the lifetime of one thread, one should use
@code
{
sql
_
alloc()
}
instead.
@item
Before making big design decisions, please first post a summary of
what you want to do, why you want to do it, and how you plan to do
it. This way we can easily provide you with feedback and also
easily discuss it thoroughly if some other developer thinks there is better
way to do the same thing!
@item
Use my
_
var as opposed to myVar or MyVar (@samp
{_}
rather than dancing SHIFT
to seperate words in identifiers).
@item
Class names start with a capital letter.
@item
Structure types are @code
{
typedef
}
'ed to an all-caps identifier.
@item
Any @code
{
#define
}
's are in all-caps.
@item
Matching @samp
{
@
{}
are in the same column.
@item
Functions return 0 on success, and non-zero on error, so you can do:
@example
if(a() || b() || c())
{
error("something went wrong");
}
@end example
@item
Using @code
{
goto
}
is okay if not abused.
@item
Avoid default variable initalizations, use @code
{
LINT
_
INIT()
}
if the
compiler complains after making sure that there is really no way
the variable can be used uninitialized.
@item
Do not instantiate a class if you do not have to.
@item
Use pointers rather than array indexing when operating on strings.
@end itemize
@c The Index was empty, and ugly, so I removed it. (jcole, Sep 7, 2000)
@c @node Index
@c @unnumbered Index
@c @printindex fn
@summarycontents
@summarycontents
@contents
@contents
...
...
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