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
50b928b0
Commit
50b928b0
authored
Nov 13, 2014
by
Rich Prohaska
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DB-759 test and fix alter table bug with cardinality data
parent
2494bde7
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
332 additions
and
14 deletions
+332
-14
mysql-test/suite/tokudb/r/card_drop_index_2.result
mysql-test/suite/tokudb/r/card_drop_index_2.result
+158
-0
mysql-test/suite/tokudb/t/card_drop_index_2.test
mysql-test/suite/tokudb/t/card_drop_index_2.test
+35
-0
storage/tokudb/ha_tokudb_alter_56.cc
storage/tokudb/ha_tokudb_alter_56.cc
+1
-1
storage/tokudb/tests/card_test_alter.cc
storage/tokudb/tests/card_test_alter.cc
+131
-11
storage/tokudb/tokudb_card.h
storage/tokudb/tokudb_card.h
+7
-2
No files found.
mysql-test/suite/tokudb/r/card_drop_index_2.result
0 → 100644
View file @
50b928b0
This diff is collapsed.
Click to expand it.
mysql-test/suite/tokudb/t/card_drop_index_2.test
0 → 100644
View file @
50b928b0
# test that add index keeps cardinality for older indexes
source
include
/
have_tokudb
.
inc
;
set
default_storage_engine
=
'tokudb'
;
disable_warnings
;
drop
table
if
exists
tt
;
enable_warnings
;
create
table
tt
(
a
int
,
b
int
,
c
int
,
primary
key
(
a
),
key
(
b
),
key
(
c
));
let
$a
=
0
;
while
(
$a
<
500
)
{
eval
insert
into
tt
values
(
$a
,
$a
,
0
),
(
$a
+
1
,
$a
,
0
),
(
$a
+
2
,
$a
,
0
),
(
$a
+
3
,
$a
,
0
);
inc
$a
;
inc
$a
;
inc
$a
;
inc
$a
;
}
select
count
(
*
)
from
tt
;
# compute cardinality
show
indexes
from
tt
;
analyze
table
tt
;
show
indexes
from
tt
;
# drop key b
alter
table
tt
drop
key
b
;
show
indexes
from
tt
;
# drop key c
alter
table
tt
drop
key
c
;
show
indexes
from
tt
;
# test that cardinality is persistent
flush
tables
;
show
indexes
from
tt
;
drop
table
tt
;
storage/tokudb/ha_tokudb_alter_56.cc
View file @
50b928b0
...
...
@@ -528,7 +528,7 @@ bool ha_tokudb::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha
error
=
alter_table_expand_blobs
(
altered_table
,
ha_alter_info
);
if
(
error
==
0
&&
ctx
->
reset_card
)
{
error
=
tokudb
::
set_card_from_status
(
share
->
status_block
,
ctx
->
alter_txn
,
table
->
s
,
altered_table
->
s
);
error
=
tokudb
::
alter_card
(
share
->
status_block
,
ctx
->
alter_txn
,
table
->
s
,
altered_table
->
s
);
}
if
(
error
==
0
&&
ctx
->
optimize_needed
)
{
error
=
do_optimize
(
ha_thd
());
...
...
storage/tokudb/tests/card_test_alter.cc
View file @
50b928b0
...
...
@@ -357,6 +357,65 @@ static void test_drop_2(DB_ENV *env) {
assert
(
error
==
0
);
}
static
void
test_drop_1_multiple_parts
(
DB_ENV
*
env
)
{
int
error
;
DB_TXN
*
txn
=
NULL
;
error
=
env
->
txn_begin
(
env
,
NULL
,
&
txn
,
0
);
assert
(
error
==
0
);
DB
*
status_db
=
NULL
;
error
=
tokudb
::
create_status
(
env
,
&
status_db
,
"status_drop_1_multiple_parts"
,
txn
);
assert
(
error
==
0
);
// define tables
const
uint
ta_keys
=
3
;
const
uint
ta_key_parts
=
1
+
2
+
3
;
const
uint
ta_rec_per_keys
=
ta_key_parts
;
uint64_t
ta_rec_per_key
[
ta_rec_per_keys
]
=
{
1000
,
2000
,
2001
,
3000
,
3001
,
3002
,
};
KEY_INFO
ta_key_info
[
ta_rec_per_keys
]
=
{
{
0
,
1
,
&
ta_rec_per_key
[
0
],
(
char
*
)
"key_a"
},
{
0
,
2
,
&
ta_rec_per_key
[
0
+
1
],
(
char
*
)
"key_b"
},
{
0
,
3
,
&
ta_rec_per_key
[
0
+
1
+
2
],
(
char
*
)
"key_c"
},
};
TABLE_SHARE
ta
=
{
MAX_KEY
,
ta_keys
,
ta_key_parts
,
ta_key_info
};
const
uint
tb_keys
=
2
;
const
uint
tb_key_parts
=
1
+
3
;
const
int
tb_rec_per_keys
=
tb_key_parts
;
uint64_t
tb_rec_per_key
[
tb_rec_per_keys
]
=
{
1000
,
3000
,
3001
,
3002
,
};
KEY_INFO
tb_key_info
[
tb_rec_per_keys
]
=
{
{
0
,
1
,
&
tb_rec_per_key
[
0
],
(
char
*
)
"key_a"
},
{
0
,
3
,
&
tb_rec_per_key
[
0
+
1
],
(
char
*
)
"key_c"
},
};
TABLE_SHARE
tb
=
{
MAX_KEY
,
tb_keys
,
tb_key_parts
,
tb_key_info
};
// set initial cardinality
error
=
tokudb
::
set_card_in_status
(
status_db
,
txn
,
ta_rec_per_keys
,
ta_rec_per_key
);
assert
(
error
==
0
);
error
=
tokudb
::
alter_card
(
status_db
,
txn
,
&
ta
,
&
tb
);
assert
(
error
==
0
);
// verify
uint64_t
current_rec_per_key
[
tb_rec_per_keys
];
error
=
tokudb
::
get_card_from_status
(
status_db
,
txn
,
tb_rec_per_keys
,
current_rec_per_key
);
assert
(
error
==
0
);
for
(
uint
i
=
0
;
i
<
tb_rec_per_keys
;
i
++
)
{
assert
(
current_rec_per_key
[
i
]
==
tb_rec_per_key
[
i
]);
}
error
=
txn
->
commit
(
txn
,
0
);
assert
(
error
==
0
);
error
=
tokudb
::
close_status
(
&
status_db
);
assert
(
error
==
0
);
}
static
void
test_add_0
(
DB_ENV
*
env
)
{
int
error
;
...
...
@@ -534,6 +593,65 @@ static void test_add_2(DB_ENV *env) {
assert
(
error
==
0
);
}
static
void
test_add_0_multiple_parts
(
DB_ENV
*
env
)
{
int
error
;
DB_TXN
*
txn
=
NULL
;
error
=
env
->
txn_begin
(
env
,
NULL
,
&
txn
,
0
);
assert
(
error
==
0
);
DB
*
status_db
=
NULL
;
error
=
tokudb
::
create_status
(
env
,
&
status_db
,
"status_add_0_multiple_parts"
,
txn
);
assert
(
error
==
0
);
// define tables
const
uint
ta_keys
=
2
;
const
uint
ta_key_parts
=
3
+
4
;
const
uint
ta_rec_per_keys
=
ta_key_parts
;
uint64_t
ta_rec_per_key
[
ta_rec_per_keys
]
=
{
2000
,
2001
,
2002
,
3000
,
3001
,
3002
,
3003
,
};
KEY_INFO
ta_key_info
[
ta_rec_per_keys
]
=
{
{
0
,
3
,
&
ta_rec_per_key
[
0
],
(
char
*
)
"key_b"
},
{
0
,
4
,
&
ta_rec_per_key
[
3
],
(
char
*
)
"key_c"
},
};
TABLE_SHARE
ta
=
{
MAX_KEY
,
ta_keys
,
ta_key_parts
,
ta_key_info
};
const
uint
tb_keys
=
3
;
const
uint
tb_key_parts
=
2
+
3
+
4
;
const
int
tb_rec_per_keys
=
tb_key_parts
;
uint64_t
tb_rec_per_key
[
tb_rec_per_keys
]
=
{
0
,
0
/*not computed*/
,
2000
,
2001
,
2002
,
3000
,
3001
,
3002
,
3003
,
};
KEY_INFO
tb_key_info
[
tb_rec_per_keys
]
=
{
{
0
,
2
,
&
tb_rec_per_key
[
0
],
(
char
*
)
"key_a"
},
{
0
,
3
,
&
tb_rec_per_key
[
0
+
2
],
(
char
*
)
"key_b"
},
{
0
,
4
,
&
tb_rec_per_key
[
0
+
2
+
3
],
(
char
*
)
"key_c"
},
};
TABLE_SHARE
tb
=
{
MAX_KEY
,
tb_keys
,
tb_key_parts
,
tb_key_info
};
// set initial cardinality
error
=
tokudb
::
set_card_in_status
(
status_db
,
txn
,
ta_rec_per_keys
,
ta_rec_per_key
);
assert
(
error
==
0
);
error
=
tokudb
::
alter_card
(
status_db
,
txn
,
&
ta
,
&
tb
);
assert
(
error
==
0
);
// verify
uint64_t
current_rec_per_key
[
tb_rec_per_keys
];
error
=
tokudb
::
get_card_from_status
(
status_db
,
txn
,
tb_rec_per_keys
,
current_rec_per_key
);
assert
(
error
==
0
);
for
(
uint
i
=
0
;
i
<
tb_rec_per_keys
;
i
++
)
{
assert
(
current_rec_per_key
[
i
]
==
tb_rec_per_key
[
i
]);
}
error
=
txn
->
commit
(
txn
,
0
);
assert
(
error
==
0
);
error
=
tokudb
::
close_status
(
&
status_db
);
assert
(
error
==
0
);
}
int
main
()
{
int
error
;
...
...
@@ -555,9 +673,11 @@ int main() {
test_drop_0
(
env
);
test_drop_1
(
env
);
test_drop_2
(
env
);
test_drop_1_multiple_parts
(
env
);
test_add_0
(
env
);
test_add_1
(
env
);
test_add_2
(
env
);
test_add_0_multiple_parts
(
env
);
error
=
env
->
close
(
env
,
0
);
assert
(
error
==
0
);
...
...
storage/tokudb/tokudb_card.h
View file @
50b928b0
...
...
@@ -174,9 +174,14 @@ namespace tokudb {
return
false
;
}
static
void
copy_card
(
uint64_t
*
dest
,
uint64_t
*
src
,
size_t
n
)
{
for
(
size_t
i
=
0
;
i
<
n
;
i
++
)
dest
[
i
]
=
src
[
i
];
}
// Altered table cardinality = select cardinality data from current table cardinality for keys that exist
// in the altered table and the current table.
int
set_card_from_status
(
DB
*
status_db
,
DB_TXN
*
txn
,
TABLE_SHARE
*
table_share
,
TABLE_SHARE
*
altered_table_share
)
{
int
alter_card
(
DB
*
status_db
,
DB_TXN
*
txn
,
TABLE_SHARE
*
table_share
,
TABLE_SHARE
*
altered_table_share
)
{
int
error
;
// read existing cardinality data from status
uint
table_total_key_parts
=
tokudb
::
compute_total_key_parts
(
table_share
);
...
...
@@ -201,7 +206,7 @@ namespace tokudb {
uint
ith_key_parts
=
get_key_parts
(
&
altered_table_share
->
key_info
[
i
]);
uint
orig_key_index
;
if
(
find_index_of_key
(
altered_table_share
->
key_info
[
i
].
name
,
table_share
,
&
orig_key_index
))
{
memcpy
(
&
altered_rec_per_key
[
next_key_parts
],
&
rec_per_key
[
orig_key_offset
[
orig_key_index
]],
ith_key_parts
);
copy_card
(
&
altered_rec_per_key
[
next_key_parts
],
&
rec_per_key
[
orig_key_offset
[
orig_key_index
]],
ith_key_parts
);
}
next_key_parts
+=
ith_key_parts
;
}
...
...
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