Commit a4e20cfd authored by Rich Prohaska's avatar Rich Prohaska

Merge branch 'master' into releases/tokudb-7.5

parents 7b269f8a 50b928b0
set default_storage_engine='tokudb';
drop table if exists tt;
create table tt (a int, b int, c int, primary key(a), key(b), key(c));
insert into tt values (0, 0, 0), (0+1, 0, 0), (0+2, 0, 0), (0+3, 0, 0);
insert into tt values (4, 4, 0), (4+1, 4, 0), (4+2, 4, 0), (4+3, 4, 0);
insert into tt values (8, 8, 0), (8+1, 8, 0), (8+2, 8, 0), (8+3, 8, 0);
insert into tt values (12, 12, 0), (12+1, 12, 0), (12+2, 12, 0), (12+3, 12, 0);
insert into tt values (16, 16, 0), (16+1, 16, 0), (16+2, 16, 0), (16+3, 16, 0);
insert into tt values (20, 20, 0), (20+1, 20, 0), (20+2, 20, 0), (20+3, 20, 0);
insert into tt values (24, 24, 0), (24+1, 24, 0), (24+2, 24, 0), (24+3, 24, 0);
insert into tt values (28, 28, 0), (28+1, 28, 0), (28+2, 28, 0), (28+3, 28, 0);
insert into tt values (32, 32, 0), (32+1, 32, 0), (32+2, 32, 0), (32+3, 32, 0);
insert into tt values (36, 36, 0), (36+1, 36, 0), (36+2, 36, 0), (36+3, 36, 0);
insert into tt values (40, 40, 0), (40+1, 40, 0), (40+2, 40, 0), (40+3, 40, 0);
insert into tt values (44, 44, 0), (44+1, 44, 0), (44+2, 44, 0), (44+3, 44, 0);
insert into tt values (48, 48, 0), (48+1, 48, 0), (48+2, 48, 0), (48+3, 48, 0);
insert into tt values (52, 52, 0), (52+1, 52, 0), (52+2, 52, 0), (52+3, 52, 0);
insert into tt values (56, 56, 0), (56+1, 56, 0), (56+2, 56, 0), (56+3, 56, 0);
insert into tt values (60, 60, 0), (60+1, 60, 0), (60+2, 60, 0), (60+3, 60, 0);
insert into tt values (64, 64, 0), (64+1, 64, 0), (64+2, 64, 0), (64+3, 64, 0);
insert into tt values (68, 68, 0), (68+1, 68, 0), (68+2, 68, 0), (68+3, 68, 0);
insert into tt values (72, 72, 0), (72+1, 72, 0), (72+2, 72, 0), (72+3, 72, 0);
insert into tt values (76, 76, 0), (76+1, 76, 0), (76+2, 76, 0), (76+3, 76, 0);
insert into tt values (80, 80, 0), (80+1, 80, 0), (80+2, 80, 0), (80+3, 80, 0);
insert into tt values (84, 84, 0), (84+1, 84, 0), (84+2, 84, 0), (84+3, 84, 0);
insert into tt values (88, 88, 0), (88+1, 88, 0), (88+2, 88, 0), (88+3, 88, 0);
insert into tt values (92, 92, 0), (92+1, 92, 0), (92+2, 92, 0), (92+3, 92, 0);
insert into tt values (96, 96, 0), (96+1, 96, 0), (96+2, 96, 0), (96+3, 96, 0);
insert into tt values (100, 100, 0), (100+1, 100, 0), (100+2, 100, 0), (100+3, 100, 0);
insert into tt values (104, 104, 0), (104+1, 104, 0), (104+2, 104, 0), (104+3, 104, 0);
insert into tt values (108, 108, 0), (108+1, 108, 0), (108+2, 108, 0), (108+3, 108, 0);
insert into tt values (112, 112, 0), (112+1, 112, 0), (112+2, 112, 0), (112+3, 112, 0);
insert into tt values (116, 116, 0), (116+1, 116, 0), (116+2, 116, 0), (116+3, 116, 0);
insert into tt values (120, 120, 0), (120+1, 120, 0), (120+2, 120, 0), (120+3, 120, 0);
insert into tt values (124, 124, 0), (124+1, 124, 0), (124+2, 124, 0), (124+3, 124, 0);
insert into tt values (128, 128, 0), (128+1, 128, 0), (128+2, 128, 0), (128+3, 128, 0);
insert into tt values (132, 132, 0), (132+1, 132, 0), (132+2, 132, 0), (132+3, 132, 0);
insert into tt values (136, 136, 0), (136+1, 136, 0), (136+2, 136, 0), (136+3, 136, 0);
insert into tt values (140, 140, 0), (140+1, 140, 0), (140+2, 140, 0), (140+3, 140, 0);
insert into tt values (144, 144, 0), (144+1, 144, 0), (144+2, 144, 0), (144+3, 144, 0);
insert into tt values (148, 148, 0), (148+1, 148, 0), (148+2, 148, 0), (148+3, 148, 0);
insert into tt values (152, 152, 0), (152+1, 152, 0), (152+2, 152, 0), (152+3, 152, 0);
insert into tt values (156, 156, 0), (156+1, 156, 0), (156+2, 156, 0), (156+3, 156, 0);
insert into tt values (160, 160, 0), (160+1, 160, 0), (160+2, 160, 0), (160+3, 160, 0);
insert into tt values (164, 164, 0), (164+1, 164, 0), (164+2, 164, 0), (164+3, 164, 0);
insert into tt values (168, 168, 0), (168+1, 168, 0), (168+2, 168, 0), (168+3, 168, 0);
insert into tt values (172, 172, 0), (172+1, 172, 0), (172+2, 172, 0), (172+3, 172, 0);
insert into tt values (176, 176, 0), (176+1, 176, 0), (176+2, 176, 0), (176+3, 176, 0);
insert into tt values (180, 180, 0), (180+1, 180, 0), (180+2, 180, 0), (180+3, 180, 0);
insert into tt values (184, 184, 0), (184+1, 184, 0), (184+2, 184, 0), (184+3, 184, 0);
insert into tt values (188, 188, 0), (188+1, 188, 0), (188+2, 188, 0), (188+3, 188, 0);
insert into tt values (192, 192, 0), (192+1, 192, 0), (192+2, 192, 0), (192+3, 192, 0);
insert into tt values (196, 196, 0), (196+1, 196, 0), (196+2, 196, 0), (196+3, 196, 0);
insert into tt values (200, 200, 0), (200+1, 200, 0), (200+2, 200, 0), (200+3, 200, 0);
insert into tt values (204, 204, 0), (204+1, 204, 0), (204+2, 204, 0), (204+3, 204, 0);
insert into tt values (208, 208, 0), (208+1, 208, 0), (208+2, 208, 0), (208+3, 208, 0);
insert into tt values (212, 212, 0), (212+1, 212, 0), (212+2, 212, 0), (212+3, 212, 0);
insert into tt values (216, 216, 0), (216+1, 216, 0), (216+2, 216, 0), (216+3, 216, 0);
insert into tt values (220, 220, 0), (220+1, 220, 0), (220+2, 220, 0), (220+3, 220, 0);
insert into tt values (224, 224, 0), (224+1, 224, 0), (224+2, 224, 0), (224+3, 224, 0);
insert into tt values (228, 228, 0), (228+1, 228, 0), (228+2, 228, 0), (228+3, 228, 0);
insert into tt values (232, 232, 0), (232+1, 232, 0), (232+2, 232, 0), (232+3, 232, 0);
insert into tt values (236, 236, 0), (236+1, 236, 0), (236+2, 236, 0), (236+3, 236, 0);
insert into tt values (240, 240, 0), (240+1, 240, 0), (240+2, 240, 0), (240+3, 240, 0);
insert into tt values (244, 244, 0), (244+1, 244, 0), (244+2, 244, 0), (244+3, 244, 0);
insert into tt values (248, 248, 0), (248+1, 248, 0), (248+2, 248, 0), (248+3, 248, 0);
insert into tt values (252, 252, 0), (252+1, 252, 0), (252+2, 252, 0), (252+3, 252, 0);
insert into tt values (256, 256, 0), (256+1, 256, 0), (256+2, 256, 0), (256+3, 256, 0);
insert into tt values (260, 260, 0), (260+1, 260, 0), (260+2, 260, 0), (260+3, 260, 0);
insert into tt values (264, 264, 0), (264+1, 264, 0), (264+2, 264, 0), (264+3, 264, 0);
insert into tt values (268, 268, 0), (268+1, 268, 0), (268+2, 268, 0), (268+3, 268, 0);
insert into tt values (272, 272, 0), (272+1, 272, 0), (272+2, 272, 0), (272+3, 272, 0);
insert into tt values (276, 276, 0), (276+1, 276, 0), (276+2, 276, 0), (276+3, 276, 0);
insert into tt values (280, 280, 0), (280+1, 280, 0), (280+2, 280, 0), (280+3, 280, 0);
insert into tt values (284, 284, 0), (284+1, 284, 0), (284+2, 284, 0), (284+3, 284, 0);
insert into tt values (288, 288, 0), (288+1, 288, 0), (288+2, 288, 0), (288+3, 288, 0);
insert into tt values (292, 292, 0), (292+1, 292, 0), (292+2, 292, 0), (292+3, 292, 0);
insert into tt values (296, 296, 0), (296+1, 296, 0), (296+2, 296, 0), (296+3, 296, 0);
insert into tt values (300, 300, 0), (300+1, 300, 0), (300+2, 300, 0), (300+3, 300, 0);
insert into tt values (304, 304, 0), (304+1, 304, 0), (304+2, 304, 0), (304+3, 304, 0);
insert into tt values (308, 308, 0), (308+1, 308, 0), (308+2, 308, 0), (308+3, 308, 0);
insert into tt values (312, 312, 0), (312+1, 312, 0), (312+2, 312, 0), (312+3, 312, 0);
insert into tt values (316, 316, 0), (316+1, 316, 0), (316+2, 316, 0), (316+3, 316, 0);
insert into tt values (320, 320, 0), (320+1, 320, 0), (320+2, 320, 0), (320+3, 320, 0);
insert into tt values (324, 324, 0), (324+1, 324, 0), (324+2, 324, 0), (324+3, 324, 0);
insert into tt values (328, 328, 0), (328+1, 328, 0), (328+2, 328, 0), (328+3, 328, 0);
insert into tt values (332, 332, 0), (332+1, 332, 0), (332+2, 332, 0), (332+3, 332, 0);
insert into tt values (336, 336, 0), (336+1, 336, 0), (336+2, 336, 0), (336+3, 336, 0);
insert into tt values (340, 340, 0), (340+1, 340, 0), (340+2, 340, 0), (340+3, 340, 0);
insert into tt values (344, 344, 0), (344+1, 344, 0), (344+2, 344, 0), (344+3, 344, 0);
insert into tt values (348, 348, 0), (348+1, 348, 0), (348+2, 348, 0), (348+3, 348, 0);
insert into tt values (352, 352, 0), (352+1, 352, 0), (352+2, 352, 0), (352+3, 352, 0);
insert into tt values (356, 356, 0), (356+1, 356, 0), (356+2, 356, 0), (356+3, 356, 0);
insert into tt values (360, 360, 0), (360+1, 360, 0), (360+2, 360, 0), (360+3, 360, 0);
insert into tt values (364, 364, 0), (364+1, 364, 0), (364+2, 364, 0), (364+3, 364, 0);
insert into tt values (368, 368, 0), (368+1, 368, 0), (368+2, 368, 0), (368+3, 368, 0);
insert into tt values (372, 372, 0), (372+1, 372, 0), (372+2, 372, 0), (372+3, 372, 0);
insert into tt values (376, 376, 0), (376+1, 376, 0), (376+2, 376, 0), (376+3, 376, 0);
insert into tt values (380, 380, 0), (380+1, 380, 0), (380+2, 380, 0), (380+3, 380, 0);
insert into tt values (384, 384, 0), (384+1, 384, 0), (384+2, 384, 0), (384+3, 384, 0);
insert into tt values (388, 388, 0), (388+1, 388, 0), (388+2, 388, 0), (388+3, 388, 0);
insert into tt values (392, 392, 0), (392+1, 392, 0), (392+2, 392, 0), (392+3, 392, 0);
insert into tt values (396, 396, 0), (396+1, 396, 0), (396+2, 396, 0), (396+3, 396, 0);
insert into tt values (400, 400, 0), (400+1, 400, 0), (400+2, 400, 0), (400+3, 400, 0);
insert into tt values (404, 404, 0), (404+1, 404, 0), (404+2, 404, 0), (404+3, 404, 0);
insert into tt values (408, 408, 0), (408+1, 408, 0), (408+2, 408, 0), (408+3, 408, 0);
insert into tt values (412, 412, 0), (412+1, 412, 0), (412+2, 412, 0), (412+3, 412, 0);
insert into tt values (416, 416, 0), (416+1, 416, 0), (416+2, 416, 0), (416+3, 416, 0);
insert into tt values (420, 420, 0), (420+1, 420, 0), (420+2, 420, 0), (420+3, 420, 0);
insert into tt values (424, 424, 0), (424+1, 424, 0), (424+2, 424, 0), (424+3, 424, 0);
insert into tt values (428, 428, 0), (428+1, 428, 0), (428+2, 428, 0), (428+3, 428, 0);
insert into tt values (432, 432, 0), (432+1, 432, 0), (432+2, 432, 0), (432+3, 432, 0);
insert into tt values (436, 436, 0), (436+1, 436, 0), (436+2, 436, 0), (436+3, 436, 0);
insert into tt values (440, 440, 0), (440+1, 440, 0), (440+2, 440, 0), (440+3, 440, 0);
insert into tt values (444, 444, 0), (444+1, 444, 0), (444+2, 444, 0), (444+3, 444, 0);
insert into tt values (448, 448, 0), (448+1, 448, 0), (448+2, 448, 0), (448+3, 448, 0);
insert into tt values (452, 452, 0), (452+1, 452, 0), (452+2, 452, 0), (452+3, 452, 0);
insert into tt values (456, 456, 0), (456+1, 456, 0), (456+2, 456, 0), (456+3, 456, 0);
insert into tt values (460, 460, 0), (460+1, 460, 0), (460+2, 460, 0), (460+3, 460, 0);
insert into tt values (464, 464, 0), (464+1, 464, 0), (464+2, 464, 0), (464+3, 464, 0);
insert into tt values (468, 468, 0), (468+1, 468, 0), (468+2, 468, 0), (468+3, 468, 0);
insert into tt values (472, 472, 0), (472+1, 472, 0), (472+2, 472, 0), (472+3, 472, 0);
insert into tt values (476, 476, 0), (476+1, 476, 0), (476+2, 476, 0), (476+3, 476, 0);
insert into tt values (480, 480, 0), (480+1, 480, 0), (480+2, 480, 0), (480+3, 480, 0);
insert into tt values (484, 484, 0), (484+1, 484, 0), (484+2, 484, 0), (484+3, 484, 0);
insert into tt values (488, 488, 0), (488+1, 488, 0), (488+2, 488, 0), (488+3, 488, 0);
insert into tt values (492, 492, 0), (492+1, 492, 0), (492+2, 492, 0), (492+3, 492, 0);
insert into tt values (496, 496, 0), (496+1, 496, 0), (496+2, 496, 0), (496+3, 496, 0);
select count(*) from tt;
count(*)
500
show indexes from tt;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
tt 0 PRIMARY 1 a A 500 NULL NULL BTREE
tt 1 b 1 b A NULL NULL NULL YES BTREE
tt 1 c 1 c A NULL NULL NULL YES BTREE
analyze table tt;
Table Op Msg_type Msg_text
test.tt analyze status OK
show indexes from tt;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
tt 0 PRIMARY 1 a A 500 NULL NULL BTREE
tt 1 b 1 b A 125 NULL NULL YES BTREE
tt 1 c 1 c A 1 NULL NULL YES BTREE
alter table tt drop key b;
show indexes from tt;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
tt 0 PRIMARY 1 a A 500 NULL NULL BTREE
tt 1 c 1 c A 1 NULL NULL YES BTREE
alter table tt drop key c;
show indexes from tt;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
tt 0 PRIMARY 1 a A 500 NULL NULL BTREE
flush tables;
show indexes from tt;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
tt 0 PRIMARY 1 a A 500 NULL NULL BTREE
drop table tt;
# 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;
...@@ -528,7 +528,7 @@ bool ha_tokudb::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha ...@@ -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); error = alter_table_expand_blobs(altered_table, ha_alter_info);
if (error == 0 && ctx->reset_card) { 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) { if (error == 0 && ctx->optimize_needed) {
error = do_optimize(ha_thd()); error = do_optimize(ha_thd());
......
...@@ -2,7 +2,11 @@ SRCS = $(wildcard *.cc) ...@@ -2,7 +2,11 @@ SRCS = $(wildcard *.cc)
TARGETS = $(patsubst %.cc,%,$(SRCS)) TARGETS = $(patsubst %.cc,%,$(SRCS))
CHECKS = $(patsubst %,%.check,$(TARGETS)) CHECKS = $(patsubst %,%.check,$(TARGETS))
CPPFLAGS = -I.. -D__STDC_FORMAT_MACROS CPPFLAGS = -I.. -D__STDC_FORMAT_MACROS
CXXFLAGS = -g -Wall -Wextra -Wno-missing-field-initializers -Wshadow -fopenmp CXXFLAGS = -g -Wall -Wextra -Wno-missing-field-initializers -Wshadow
ifdef USE_OPENMP
CPPFLAGS += -DUSE_OPENMP
CXXFLAGS += -fopenmp
endif
FRACTALTREE_BASE_DIR = ../ft-index FRACTALTREE_BASE_DIR = ../ft-index
FRACTALTREE_INSTALL_DIR = $(FRACTALTREE_BASE_DIR)/install.debug FRACTALTREE_INSTALL_DIR = $(FRACTALTREE_BASE_DIR)/install.debug
...@@ -10,6 +14,8 @@ VALGRIND = valgrind -q --leak-check=full --show-reachable=yes --suppressions=$(F ...@@ -10,6 +14,8 @@ VALGRIND = valgrind -q --leak-check=full --show-reachable=yes --suppressions=$(F
ifeq ($(GCOV),1) ifeq ($(GCOV),1)
CXXFLAGS += -fprofile-arcs -ftest-coverage CXXFLAGS += -fprofile-arcs -ftest-coverage
else
CXXFLAGS += -O3
endif endif
all: $(TARGETS) all: $(TARGETS)
...@@ -17,21 +23,29 @@ all: $(TARGETS) ...@@ -17,21 +23,29 @@ all: $(TARGETS)
clean: clean:
rm -rf $(TARGETS) *.gcov *.gcno *.gcda *.testdir *.dSYM rm -rf $(TARGETS) *.gcov *.gcno *.gcda *.testdir *.dSYM
check: $(CHECKS)
true
%.check: % %.check: %
LD_LIBRARY_PATH=$(FRACTALTREE_INSTALL_DIR)/lib $(VALGRIND) ./$< LD_LIBRARY_PATH=$(FRACTALTREE_INSTALL_DIR)/lib $(VALGRIND) ./$<
card.check: card_test.check card_1.check card_inf.check card_inf_1.check card_random_1.check card_etime.check card.check: $(patsubst %.cc,%.check,$(wildcard card*.cc))
true
ifndef USE_OPENMP
# unravel vlq_test_uint64 8 times
vlq_test_uint64_%.check:
LD_LIBRARY_PATH=$(FRACTALTREE_INSTALL_DIR)/lib $(VALGRIND) ./vlq_test_uint64 $(patsubst vlq_test_uint64_%.check,%,$@) 8
vlq_test_uint64.check: $(foreach i,0 1 2 3 4 5 6 7,vlq_test_uint64_$(i).check)
true true
endif
vlq.check: vlq_test.check vlq_test_uint32.check vlq_test_uint64.check vlq.check: $(patsubst %.cc,%.check,$(wildcard vlq*.cc))
true true
max_test.check: max_test max_test.check: max_test
$(VALGRIND) ./$< 1 2 $(VALGRIND) ./$< 1 2
check: $(CHECKS)
true
%: %.cc %: %.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -g -o $@ $< $(CXX) $(CPPFLAGS) $(CXXFLAGS) -g -o $@ $<
......
...@@ -222,6 +222,19 @@ static void test_10(DB_ENV *env) { ...@@ -222,6 +222,19 @@ static void test_10(DB_ENV *env) {
error = txn->commit(txn, 0); error = txn->commit(txn, 0);
assert(error == 0); assert(error == 0);
// test delete card
error = env->txn_begin(env, NULL, &txn, 0);
assert(error == 0);
error = tokudb::delete_card_from_status(status_db, txn);
assert(error == 0);
error = tokudb::get_card_from_status(status_db, txn, 0, NULL);
assert(error == DB_NOTFOUND);
error = txn->commit(txn, 0);
assert(error == 0);
error = tokudb::close_status(&status_db); error = tokudb::close_status(&status_db);
assert(error == 0); assert(error == 0);
......
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
This software is covered by US Patent No. 8,489,638.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
// test tokudb cardinality in status dictionary
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <memory.h>
#include <errno.h>
#include <sys/stat.h>
#include <db.h>
typedef unsigned long long ulonglong;
#include <tokudb_status.h>
#include <tokudb_buffer.h>
#include "fake_mysql.h"
#if __APPLE__
typedef unsigned long ulong;
#endif
#include <tokudb_card.h>
static void test_no_keys(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_no_keys", txn);
assert(error == 0);
const uint keys = 0;
const uint key_parts = 0;
TABLE_SHARE s = { MAX_KEY, keys, key_parts, NULL };
error = tokudb::alter_card(status_db, txn, &s, &s);
assert(error == 0);
error = txn->commit(txn, 0);
assert(error == 0);
error = tokudb::close_status(&status_db);
assert(error == 0);
}
static void test_keys(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_keys", txn);
assert(error == 0);
// define tables
const uint ta_keys = 3;
const uint ta_key_parts = 1;
const int ta_rec_per_keys = ta_keys * ta_key_parts;
uint64_t ta_rec_per_key[ta_rec_per_keys] = {
1000, 2000, 3000,
};
KEY_INFO ta_key_info[ta_rec_per_keys] = {
{ 0, ta_key_parts, &ta_rec_per_key[0], (char *) "key_a" },
{ 0, ta_key_parts, &ta_rec_per_key[1], (char *) "key_b" },
{ 0, ta_key_parts, &ta_rec_per_key[1], (char *) "key_c" },
};
TABLE_SHARE ta = { MAX_KEY, ta_keys, ta_key_parts, ta_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, &ta);
assert(error == 0);
// verify
uint64_t current_rec_per_key[ta_rec_per_keys];
error = tokudb::get_card_from_status(status_db, txn, ta_rec_per_keys, current_rec_per_key);
assert(error == 0);
for (uint i = 0; i < ta_rec_per_keys; i++) {
assert(current_rec_per_key[i] == ta_rec_per_key[i]);
}
error = txn->commit(txn, 0);
assert(error == 0);
error = tokudb::close_status(&status_db);
assert(error == 0);
}
static void test_drop_0(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_0", txn);
assert(error == 0);
// define tables
const uint ta_keys = 3;
const uint ta_key_parts = 1;
const uint ta_rec_per_keys = ta_keys * ta_key_parts;
uint64_t ta_rec_per_key[ta_rec_per_keys] = {
1000, 2000, 3000,
};
KEY_INFO ta_key_info[ta_rec_per_keys] = {
{ 0, ta_key_parts, &ta_rec_per_key[0], (char *) "key_a" },
{ 0, ta_key_parts, &ta_rec_per_key[1], (char *) "key_b" },
{ 0, ta_key_parts, &ta_rec_per_key[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;
const int tb_rec_per_keys = tb_keys * tb_key_parts;
uint64_t tb_rec_per_key[tb_rec_per_keys] = {
2000, 3000,
};
KEY_INFO tb_key_info[tb_rec_per_keys] = {
{ 0, tb_key_parts, &tb_rec_per_key[0], (char *) "key_b" },
{ 0, tb_key_parts, &tb_rec_per_key[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_drop_1(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", txn);
assert(error == 0);
// define tables
const uint ta_keys = 3;
const uint ta_key_parts = 1;
const uint ta_rec_per_keys = ta_keys * ta_key_parts;
uint64_t ta_rec_per_key[ta_rec_per_keys] = {
1000, 2000, 3000,
};
KEY_INFO ta_key_info[ta_rec_per_keys] = {
{ 0, ta_key_parts, &ta_rec_per_key[0], (char *) "key_a" },
{ 0, ta_key_parts, &ta_rec_per_key[1], (char *) "key_b" },
{ 0, ta_key_parts, &ta_rec_per_key[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;
const int tb_rec_per_keys = tb_keys * tb_key_parts;
uint64_t tb_rec_per_key[tb_rec_per_keys] = {
1000, 3000,
};
KEY_INFO tb_key_info[tb_rec_per_keys] = {
{ 0, tb_key_parts, &tb_rec_per_key[0], (char *) "key_a" },
{ 0, tb_key_parts, &tb_rec_per_key[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_drop_2(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_2", txn);
assert(error == 0);
// define tables
const uint ta_keys = 3;
const uint ta_key_parts = 1;
const uint ta_rec_per_keys = ta_keys * ta_key_parts;
uint64_t ta_rec_per_key[ta_rec_per_keys] = {
1000, 2000, 3000,
};
KEY_INFO ta_key_info[ta_rec_per_keys] = {
{ 0, ta_key_parts, &ta_rec_per_key[0], (char *) "key_a" },
{ 0, ta_key_parts, &ta_rec_per_key[1], (char *) "key_b" },
{ 0, ta_key_parts, &ta_rec_per_key[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;
const int tb_rec_per_keys = tb_keys * tb_key_parts;
uint64_t tb_rec_per_key[tb_rec_per_keys] = {
1000, 2000,
};
KEY_INFO tb_key_info[tb_rec_per_keys] = {
{ 0, tb_key_parts, &tb_rec_per_key[0], (char *) "key_a" },
{ 0, tb_key_parts, &tb_rec_per_key[1], (char *) "key_b" },
};
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_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;
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", txn);
assert(error == 0);
// define tables
const uint ta_keys = 2;
const uint ta_key_parts = 1;
const uint ta_rec_per_keys = ta_keys * ta_key_parts;
uint64_t ta_rec_per_key[ta_rec_per_keys] = {
2000, 3000,
};
KEY_INFO ta_key_info[ta_rec_per_keys] = {
{ 0, ta_key_parts, &ta_rec_per_key[0], (char *) "key_b" },
{ 0, ta_key_parts, &ta_rec_per_key[1], (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 = 1;
const int tb_rec_per_keys = tb_keys * tb_key_parts;
uint64_t tb_rec_per_key[tb_rec_per_keys] = {
0 /*not computed*/, 2000, 3000,
};
KEY_INFO tb_key_info[tb_rec_per_keys] = {
{ 0, tb_key_parts, &tb_rec_per_key[0], (char *) "key_a" },
{ 0, tb_key_parts, &tb_rec_per_key[1], (char *) "key_b" },
{ 0, tb_key_parts, &tb_rec_per_key[2], (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_1(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_1", txn);
assert(error == 0);
// define tables
const uint ta_keys = 2;
const uint ta_key_parts = 1;
const uint ta_rec_per_keys = ta_keys * ta_key_parts;
uint64_t ta_rec_per_key[ta_rec_per_keys] = {
2000, 3000,
};
KEY_INFO ta_key_info[ta_rec_per_keys] = {
{ 0, ta_key_parts, &ta_rec_per_key[0], (char *) "key_b" },
{ 0, ta_key_parts, &ta_rec_per_key[1], (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 = 1;
const int tb_rec_per_keys = tb_keys * tb_key_parts;
uint64_t tb_rec_per_key[tb_rec_per_keys] = {
2000, 0 /*not computed*/, 3000,
};
KEY_INFO tb_key_info[tb_rec_per_keys] = {
{ 0, tb_key_parts, &tb_rec_per_key[0], (char *) "key_b" },
{ 0, tb_key_parts, &tb_rec_per_key[1], (char *) "key_a" },
{ 0, tb_key_parts, &tb_rec_per_key[2], (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_2(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_2", txn);
assert(error == 0);
// define tables
const uint ta_keys = 2;
const uint ta_key_parts = 1;
const uint ta_rec_per_keys = ta_keys * ta_key_parts;
uint64_t ta_rec_per_key[ta_rec_per_keys] = {
2000, 3000,
};
KEY_INFO ta_key_info[ta_rec_per_keys] = {
{ 0, ta_key_parts, &ta_rec_per_key[0], (char *) "key_b" },
{ 0, ta_key_parts, &ta_rec_per_key[1], (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 = 1;
const int tb_rec_per_keys = tb_keys * tb_key_parts;
uint64_t tb_rec_per_key[tb_rec_per_keys] = {
2000, 3000, 0 /*not computed*/,
};
KEY_INFO tb_key_info[tb_rec_per_keys] = {
{ 0, tb_key_parts, &tb_rec_per_key[0], (char *) "key_b" },
{ 0, tb_key_parts, &tb_rec_per_key[1], (char *) "key_c" },
{ 0, tb_key_parts, &tb_rec_per_key[2], (char *) "key_a" },
};
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_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;
error = system("rm -rf " __FILE__ ".testdir");
assert(error == 0);
error = mkdir(__FILE__ ".testdir", S_IRWXU+S_IRWXG+S_IRWXO);
assert(error == 0);
DB_ENV *env = NULL;
error = db_env_create(&env, 0);
assert(error == 0);
error = env->open(env, __FILE__ ".testdir", DB_INIT_MPOOL + DB_INIT_LOG + DB_INIT_LOCK + DB_INIT_TXN + DB_PRIVATE + DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
assert(error == 0);
test_no_keys(env);
test_keys(env);
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);
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
This software is covered by US Patent No. 8,489,638.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
// test tokudb cardinality in status dictionary
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <memory.h>
#include <errno.h>
#include <sys/stat.h>
#include <db.h>
typedef unsigned long long ulonglong;
#include <tokudb_status.h>
#include <tokudb_buffer.h>
#include "fake_mysql.h"
#if __APPLE__
typedef unsigned long ulong;
#endif
#include <tokudb_card.h>
static void test_no_keys() {
TABLE_SHARE s = { 0, 0, 0, NULL };
TABLE t = { &s, NULL };
assert(tokudb::compute_total_key_parts(&s) == 0);
tokudb::set_card_in_key_info(&t, 0, NULL);
}
static void test_simple_pk() {
const uint keys = 1;
const uint key_parts = 1;
uint64_t pk_rec_per_key[keys] = { 0 };
KEY_INFO pk = { 0, key_parts, pk_rec_per_key, (char *) "PRIMARY" };
TABLE_SHARE s = { 0, keys, key_parts, &pk };
TABLE t = { &s, &pk };
assert(tokudb::compute_total_key_parts(&s) == key_parts);
uint64_t computed_rec_per_key[keys] = { 2 };
tokudb::set_card_in_key_info(&t, keys, computed_rec_per_key);
assert(t.key_info[0].rec_per_key[0] == 1);
}
static void test_pk_2() {
const uint keys = 1;
const uint key_parts = 2;
uint64_t pk_rec_per_key[keys * key_parts] = { 0 };
KEY_INFO pk = { 0, key_parts, pk_rec_per_key, (char *) "PRIMARY" };
TABLE_SHARE s = { 0, keys, key_parts, &pk };
TABLE t = { &s, &pk };
assert(tokudb::compute_total_key_parts(&s) == key_parts);
uint64_t computed_rec_per_key[keys * key_parts] = { 2, 3 };
tokudb::set_card_in_key_info(&t, keys * key_parts, computed_rec_per_key);
assert(t.key_info[0].rec_per_key[0] == 2);
assert(t.key_info[0].rec_per_key[1] == 1);
}
static void test_simple_sk() {
const uint keys = 1;
const uint key_parts = 1;
uint64_t sk_rec_per_key[keys] = { 0 };
KEY_INFO sk = { 0, keys, sk_rec_per_key, (char *) "KEY" };
TABLE_SHARE s = { MAX_KEY, keys, key_parts, &sk };
TABLE t = { &s, &sk };
assert(tokudb::compute_total_key_parts(&s) == 1);
uint64_t computed_rec_per_key[keys] = { 2 };
tokudb::set_card_in_key_info(&t, keys, computed_rec_per_key);
assert(t.key_info[0].rec_per_key[0] == 2);
}
static void test_simple_unique_sk() {
const uint keys = 1;
uint64_t sk_rec_per_key[keys] = { 0 };
KEY_INFO sk = { HA_NOSAME, keys, sk_rec_per_key, (char *) "KEY" };
TABLE_SHARE s = { MAX_KEY, keys, keys, &sk };
TABLE t = { &s, &sk };
assert(tokudb::compute_total_key_parts(&s) == 1);
uint64_t computed_rec_per_key[keys] = { 2 };
tokudb::set_card_in_key_info(&t, keys, computed_rec_per_key);
assert(t.key_info[0].rec_per_key[0] == 1);
}
static void test_simple_pk_sk() {
const uint keys = 2;
uint64_t rec_per_key[keys] = { 0 };
KEY_INFO key_info[keys] = {
{ 0, 1, &rec_per_key[0], (char *) "PRIMARY" },
{ 0, 1, &rec_per_key[1], (char *) "KEY" },
};
TABLE_SHARE s = { 0, keys, keys, key_info };
TABLE t = { &s, key_info };
assert(tokudb::compute_total_key_parts(&s) == 2);
uint64_t computed_rec_per_key[keys] = { 100, 200 };
tokudb::set_card_in_key_info(&t, keys, computed_rec_per_key);
assert(t.key_info[0].rec_per_key[0] == 1);
assert(t.key_info[1].rec_per_key[0] == 200);
}
static void test_simple_sk_pk() {
const uint keys = 2;
uint64_t rec_per_key[keys] = { 0 };
KEY_INFO key_info[keys] = {
{ 0, 1, &rec_per_key[0], (char *) "KEY" },
{ 0, 1, &rec_per_key[1], (char *) "PRIMARY" },
};
TABLE_SHARE s = { 1, keys, keys, key_info };
TABLE t = { &s, key_info };
assert(tokudb::compute_total_key_parts(&s) == 2);
uint64_t computed_rec_per_key[keys] = { 100, 200 };
tokudb::set_card_in_key_info(&t, keys, computed_rec_per_key);
assert(t.key_info[0].rec_per_key[0] == 100);
assert(t.key_info[1].rec_per_key[0] == 1);
}
int main() {
test_no_keys();
test_simple_pk();
test_pk_2();
test_simple_sk();
test_simple_unique_sk();
test_simple_pk_sk();
test_simple_sk_pk();
return 0;
}
...@@ -110,5 +110,6 @@ class TABLE { ...@@ -110,5 +110,6 @@ class TABLE {
}; };
uint get_key_parts(KEY_INFO *key_info) { uint get_key_parts(KEY_INFO *key_info) {
assert(key_info); assert(key_info);
return 0; return key_info->key_parts;
} }
#define MAX_KEY (1U << 30)
...@@ -101,9 +101,11 @@ namespace tokudb { ...@@ -101,9 +101,11 @@ namespace tokudb {
template size_t vlq_decode_ui(uint64_t *np, void *p, size_t s); template size_t vlq_decode_ui(uint64_t *np, void *p, size_t s);
}; };
static void test_vlq_uint64(void) { // test a slice of the number space where the slice is described by
// a start number and a stride through the space.
static void test_vlq_uint64(uint64_t start, uint64_t stride) {
printf("%u\n", 0); printf("%u\n", 0);
for (uint64_t v = 0; v < (1<<7); v++) { for (uint64_t v = 0 + start; v < (1<<7); v += stride) {
unsigned char b[10]; unsigned char b[10];
size_t out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b); size_t out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
assert(out_s == 1); assert(out_s == 1);
...@@ -113,7 +115,7 @@ static void test_vlq_uint64(void) { ...@@ -113,7 +115,7 @@ static void test_vlq_uint64(void) {
} }
printf("%u\n", 1<<7); printf("%u\n", 1<<7);
for (uint64_t v = (1<<7); v < (1<<14); v++) { for (uint64_t v = (1<<7) + start; v < (1<<14); v += stride) {
unsigned char b[10]; unsigned char b[10];
size_t out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b); size_t out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
assert(out_s == 2); assert(out_s == 2);
...@@ -123,7 +125,7 @@ static void test_vlq_uint64(void) { ...@@ -123,7 +125,7 @@ static void test_vlq_uint64(void) {
} }
printf("%u\n", 1<<14); printf("%u\n", 1<<14);
for (uint64_t v = (1<<14); v < (1<<21); v++) { for (uint64_t v = (1<<14) + start; v < (1<<21); v += stride) {
unsigned char b[10]; unsigned char b[10];
size_t out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b); size_t out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
assert(out_s == 3); assert(out_s == 3);
...@@ -133,7 +135,7 @@ static void test_vlq_uint64(void) { ...@@ -133,7 +135,7 @@ static void test_vlq_uint64(void) {
} }
printf("%u\n", 1<<21); printf("%u\n", 1<<21);
for (uint64_t v = (1<<21); v < (1<<28); v++) { for (uint64_t v = (1<<21) + start; v < (1<<28); v += stride) {
unsigned char b[10]; unsigned char b[10];
size_t out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b); size_t out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
assert(out_s == 4); assert(out_s == 4);
...@@ -143,9 +145,11 @@ static void test_vlq_uint64(void) { ...@@ -143,9 +145,11 @@ static void test_vlq_uint64(void) {
} }
printf("%u\n", 1<<28); printf("%u\n", 1<<28);
#if USE_OPENMP
#pragma omp parallel num_threads(4) #pragma omp parallel num_threads(4)
#pragma omp for #pragma omp for
for (uint64_t v = (1<<28); v < (1ULL<<35); v++) { #endif
for (uint64_t v = (1<<28) + start; v < (1ULL<<35); v += stride) {
unsigned char b[10]; unsigned char b[10];
size_t out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b); size_t out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
assert(out_s == 5); assert(out_s == 5);
...@@ -155,7 +159,12 @@ static void test_vlq_uint64(void) { ...@@ -155,7 +159,12 @@ static void test_vlq_uint64(void) {
} }
} }
int main(void) { int main(int argc, char *argv[]) {
test_vlq_uint64(); uint64_t start = 0, stride = 1;
if (argc == 3) {
start = atoll(argv[1]);
stride = atoll(argv[2]);
}
test_vlq_uint64(start, stride);
return 0; return 0;
} }
...@@ -174,9 +174,14 @@ namespace tokudb { ...@@ -174,9 +174,14 @@ namespace tokudb {
return false; 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 // Altered table cardinality = select cardinality data from current table cardinality for keys that exist
// in the altered table and the current table. // 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; int error;
// read existing cardinality data from status // read existing cardinality data from status
uint table_total_key_parts = tokudb::compute_total_key_parts(table_share); uint table_total_key_parts = tokudb::compute_total_key_parts(table_share);
...@@ -201,7 +206,7 @@ namespace tokudb { ...@@ -201,7 +206,7 @@ namespace tokudb {
uint ith_key_parts = get_key_parts(&altered_table_share->key_info[i]); uint ith_key_parts = get_key_parts(&altered_table_share->key_info[i]);
uint orig_key_index; uint orig_key_index;
if (find_index_of_key(altered_table_share->key_info[i].name, table_share, &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; next_key_parts += ith_key_parts;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment