mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
f0f2072d1f
Reason for the problem was that the hash of changed files in the key cache was too small (was 128). Fixed by making the hash size larger and changeable. - Introduced key-cache-file-hash-size (default 512) for MyISAM and aria_pagecache_file_hash_size (default 512) for Aria. - Added new status variable "Feature_delay_key_write" which counts number of tables opened that are using delay_key_write mysql-test/r/features.result: Added test of Feature_delay_key_write mysql-test/r/key_cache.result: Updated tests as the number of blocks has changed mysql-test/r/mysqld--help.result: Updated result mysql-test/suite/maria/maria3.result: Updated result mysql-test/suite/sys_vars/r/key_cache_file_hash_size_basic.result: Test new variable mysql-test/suite/sys_vars/t/aria_pagecache_file_hash_size_basic.test: Test new variable mysql-test/suite/sys_vars/t/key_cache_file_hash_size_basic.test: Test new variable mysql-test/t/features.test: Added test of Feature_delay_key_write mysql-test/t/key_cache.test: Updated tests as the number of blocks has changed mysys/mf_keycache.c: Made CHANGED_BLOCKS_HASH dynamic sql/handler.cc: Updated call to init_key_cache() sql/mysqld.cc: Added "Feature_delay_key_write" Added support for key-cache-file-hash-size sql/mysqld.h: Added support for key-cache-file-hash-size sql/sql_class.h: Added feature_files_opened_with_delayed_keys sql/sys_vars.cc: Added key_cache_file_hash_size storage/maria/ha_maria.cc: Added pagecache_file_hash_size Added counting of files with delay_key_write storage/maria/ma_checkpoint.c: Fixed compiler warning storage/maria/ma_pagecache.c: Made PAGECACHE_CHANGED_BLOCKS_HASH into a variable storage/maria/ma_pagecache.h: Made PAGECACHE_CHANGED_BLOCKS_HASH into a variable storage/maria/ma_rt_test.c: Updated parameters for init_pagecache() storage/maria/ma_test1.c: Updated parameters for init_pagecache() storage/maria/ma_test2.c: Updated parameters for init_pagecache() storage/maria/ma_test3.c: Updated parameters for init_pagecache() storage/maria/maria_chk.c: Updated parameters for init_pagecache() storage/maria/maria_ftdump.c: Updated parameters for init_pagecache() storage/maria/maria_pack.c: Updated parameters for init_pagecache() storage/maria/maria_read_log.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_pagecache_consist.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_pagecache_rwconsist.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_pagecache_rwconsist2.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_pagecache_single.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_test_loghandler-t.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_test_loghandler_first_lsn-t.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_test_loghandler_max_lsn-t.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_test_loghandler_multigroup-t.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_test_loghandler_multithread-t.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_test_loghandler_noflush-t.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_test_loghandler_nologs-t.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_test_loghandler_pagecache-t.c: Updated parameters for init_pagecache() storage/maria/unittest/ma_test_loghandler_purge-t.c: Updated parameters for init_pagecache() storage/myisam/ha_myisam.cc: Added counting of files with delay_key_write storage/myisam/mi_check.c: Updated call to init_key_cache() storage/myisam/mi_test1.c: Updated call to init_key_cache() storage/myisam/mi_test2.c: Updated call to init_key_cache() storage/myisam/mi_test3.c: Updated call to init_key_cache() storage/myisam/mi_test_all.sh: Fixed broken test storage/myisam/myisam_ftdump.c: Updated call to init_key_cache() storage/myisam/myisamchk.c: Updated call to init_key_cache() storage/myisam/myisamlog.c: Updated call to init_key_cache()
277 lines
6.8 KiB
C
277 lines
6.8 KiB
C
/*
|
|
Copyright (c) 2001, 2010, Oracle and/or its affiliates
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
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.
|
|
|
|
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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
|
|
/* Written by Sergei A. Golubchik, who has a shared copyright to this code
|
|
added support for long options (my_getopt) 22.5.2002 by Jani Tolonen */
|
|
|
|
#include "ftdefs.h"
|
|
#include <my_getopt.h>
|
|
|
|
static void usage();
|
|
static void complain(int val);
|
|
static my_bool get_one_option(int, const struct my_option *, char *);
|
|
|
|
static int count=0, stats=0, dump=0, lstats=0;
|
|
static my_bool verbose;
|
|
static char *query=NULL;
|
|
static uint lengths[256];
|
|
|
|
#define MAX_LEN (HA_FT_MAXBYTELEN+10)
|
|
#define HOW_OFTEN_TO_WRITE 10000
|
|
|
|
static struct my_option my_long_options[] =
|
|
{
|
|
{"help", 'h', "Display help and exit.",
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"help", '?', "Synonym for -h.",
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"count", 'c', "Calculate per-word stats (counts and global weights).",
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"dump", 'd', "Dump index (incl. data offsets and word weights).",
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"length", 'l', "Report length distribution.",
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"stats", 's', "Report global stats.",
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{"verbose", 'v', "Be verbose.",
|
|
&verbose, &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
|
|
};
|
|
|
|
|
|
int main(int argc,char *argv[])
|
|
{
|
|
int error=0;
|
|
uint keylen, keylen2=0, inx, doc_cnt=0;
|
|
float weight= 1.0;
|
|
double gws, min_gws=0, avg_gws=0;
|
|
MI_INFO *info;
|
|
char buf[MAX_LEN], buf2[MAX_LEN], buf_maxlen[MAX_LEN], buf_min_gws[MAX_LEN];
|
|
ulong total=0, maxlen=0, uniq=0, max_doc_cnt=0;
|
|
struct { MI_INFO *info; } aio0, *aio=&aio0; /* for GWS_IN_USE */
|
|
|
|
MY_INIT(argv[0]);
|
|
if ((error= handle_options(&argc, &argv, my_long_options, get_one_option)))
|
|
exit(error);
|
|
if (count || dump)
|
|
verbose=0;
|
|
if (!count && !dump && !lstats && !query)
|
|
stats=1;
|
|
|
|
if (verbose)
|
|
setbuf(stdout,NULL);
|
|
|
|
if (argc < 2)
|
|
usage();
|
|
|
|
{
|
|
char *end;
|
|
inx= (uint) strtoll(argv[1], &end, 10);
|
|
if (*end)
|
|
usage();
|
|
}
|
|
|
|
init_key_cache(dflt_key_cache, MI_KEY_BLOCK_LENGTH, KEY_BUFFER_INIT, 0, 0, 0, 0);
|
|
|
|
if (!(info=mi_open(argv[0], O_RDONLY,
|
|
HA_OPEN_ABORT_IF_LOCKED|HA_OPEN_FROM_SQL_LAYER)))
|
|
{
|
|
error=my_errno;
|
|
goto err;
|
|
}
|
|
|
|
*buf2=0;
|
|
aio->info=info;
|
|
|
|
if ((inx >= info->s->base.keys) ||
|
|
!(info->s->keyinfo[inx].flag & HA_FULLTEXT))
|
|
{
|
|
printf("Key %d in table %s is not a FULLTEXT key\n", inx, info->filename);
|
|
goto err;
|
|
}
|
|
|
|
mi_lock_database(info, F_EXTRA_LCK);
|
|
|
|
info->lastpos= HA_OFFSET_ERROR;
|
|
info->update|= HA_STATE_PREV_FOUND;
|
|
|
|
while (!(error=mi_rnext(info,NULL,inx)))
|
|
{
|
|
FT_WEIGTH subkeys;
|
|
keylen=*(info->lastkey);
|
|
|
|
subkeys.i =ft_sintXkorr(info->lastkey+keylen+1);
|
|
if (subkeys.i >= 0)
|
|
weight= subkeys.f;
|
|
|
|
#ifdef HAVE_SNPRINTF
|
|
snprintf(buf,MAX_LEN,"%.*s",(int) keylen,info->lastkey+1);
|
|
#else
|
|
sprintf(buf,"%.*s",(int) keylen,info->lastkey+1);
|
|
#endif
|
|
my_casedn_str(default_charset_info,buf);
|
|
total++;
|
|
lengths[keylen]++;
|
|
|
|
if (count || stats)
|
|
{
|
|
if (strcmp(buf, buf2))
|
|
{
|
|
if (*buf2)
|
|
{
|
|
uniq++;
|
|
avg_gws+=gws=GWS_IN_USE;
|
|
if (count)
|
|
printf("%9u %20.7f %s\n",doc_cnt,gws,buf2);
|
|
if (maxlen<keylen2)
|
|
{
|
|
maxlen=keylen2;
|
|
strmov(buf_maxlen, buf2);
|
|
}
|
|
if (max_doc_cnt < doc_cnt)
|
|
{
|
|
max_doc_cnt=doc_cnt;
|
|
strmov(buf_min_gws, buf2);
|
|
min_gws=gws;
|
|
}
|
|
}
|
|
strmov(buf2, buf);
|
|
keylen2=keylen;
|
|
doc_cnt=0;
|
|
}
|
|
doc_cnt+= (subkeys.i >= 0 ? 1 : -subkeys.i);
|
|
}
|
|
if (dump)
|
|
{
|
|
if (subkeys.i >= 0)
|
|
printf("%9lx %20.7f %s\n", (long) info->lastpos,weight,buf);
|
|
else
|
|
printf("%9lx => %17d %s\n",(long) info->lastpos,-subkeys.i,buf);
|
|
}
|
|
if (verbose && (total%HOW_OFTEN_TO_WRITE)==0)
|
|
printf("%10ld\r",total);
|
|
}
|
|
mi_lock_database(info, F_UNLCK);
|
|
|
|
if (count || stats)
|
|
{
|
|
if (*buf2)
|
|
{
|
|
uniq++;
|
|
avg_gws+=gws=GWS_IN_USE;
|
|
if (count)
|
|
printf("%9u %20.7f %s\n",doc_cnt,gws,buf2);
|
|
if (maxlen<keylen2)
|
|
{
|
|
maxlen=keylen2;
|
|
strmov(buf_maxlen, buf2);
|
|
}
|
|
if (max_doc_cnt < doc_cnt)
|
|
{
|
|
max_doc_cnt=doc_cnt;
|
|
strmov(buf_min_gws, buf2);
|
|
min_gws=gws;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (stats)
|
|
{
|
|
count=0;
|
|
for (inx=0;inx<256;inx++)
|
|
{
|
|
count+=lengths[inx];
|
|
if ((ulong) count >= total/2)
|
|
break;
|
|
}
|
|
printf("Total rows: %lu\nTotal words: %lu\n"
|
|
"Unique words: %lu\nLongest word: %lu chars (%s)\n"
|
|
"Median length: %u\n"
|
|
"Average global weight: %f\n"
|
|
"Most common word: %lu times, weight: %f (%s)\n",
|
|
(long) info->state->records, total, uniq, maxlen, buf_maxlen,
|
|
inx, avg_gws/uniq, max_doc_cnt, min_gws, buf_min_gws);
|
|
}
|
|
if (lstats)
|
|
{
|
|
count=0;
|
|
for (inx=0; inx<256; inx++)
|
|
{
|
|
count+=lengths[inx];
|
|
if (count && lengths[inx])
|
|
printf("%3u: %10lu %5.2f%% %20lu %4.1f%%\n", inx,
|
|
(ulong) lengths[inx],100.0*lengths[inx]/total,(ulong) count,
|
|
100.0*count/total);
|
|
}
|
|
}
|
|
|
|
err:
|
|
if (error && error != HA_ERR_END_OF_FILE)
|
|
printf("got error %d\n",my_errno);
|
|
if (info)
|
|
mi_close(info);
|
|
return 0;
|
|
}
|
|
|
|
|
|
static my_bool
|
|
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
|
|
char *argument __attribute__((unused)))
|
|
{
|
|
switch(optid) {
|
|
case 'd':
|
|
dump=1;
|
|
complain(count || query);
|
|
break;
|
|
case 's':
|
|
stats=1;
|
|
complain(query!=0);
|
|
break;
|
|
case 'c':
|
|
count= 1;
|
|
complain(dump || query);
|
|
break;
|
|
case 'l':
|
|
lstats=1;
|
|
complain(query!=0);
|
|
break;
|
|
case '?':
|
|
case 'h':
|
|
usage();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
static void usage()
|
|
{
|
|
printf("Use: myisam_ftdump <table_name> <index_num>\n");
|
|
my_print_help(my_long_options);
|
|
my_print_variables(my_long_options);
|
|
exit(1);
|
|
}
|
|
|
|
|
|
static void complain(int val) /* Kinda assert :-) */
|
|
{
|
|
if (val)
|
|
{
|
|
printf("You cannot use these options together!\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
#include "mi_extrafunc.h"
|