Commit 1de4fff5 authored by monty@hundin.mysql.fi's avatar monty@hundin.mysql.fi

Update of query cache code.

Changed some sql_alloc() -> thd->alloc()
Removed a lot of compiler warnings on Linux Alpha (64 bit)
Fixed some core dumps on 64 bit systems (wrong type for packet_len)
parent 1d26537d
......@@ -18100,6 +18100,9 @@ differ somewhat:
| protocol_version | 10 |
| record_buffer | 131072 |
| query_buffer_size | 0 |
| query_cache_limit | 1048576 |
| query_cache_size | 16768060 |
| query_cache_startup_type | 1 |
| safe_show_database | OFF |
| server_id | 0 |
| skip_locking | ON |
......@@ -18497,6 +18500,18 @@ buffer to avoid a disk seeks. If not set, then it's set to the value of
The initial allocation of the query buffer. If most of your queries are
long (like when inserting blobs), you should increase this!
@item @code{query_cache_limit}
Don't cache results that are bigger than this. (Default 1M).
@item @code{query_cache_size}
The memory allocated to store results from old queries. If this is zero
the query cache is disabled.
@item @code{query_cache_startup_type}
This may have be set to 0 (cache results but don't retrieve results from
cache), 1 (cache results by defaults) or 2 (only cache @code{SELECT}'s marked
with @code{SQL_CACHE}).
@item @code{safe_show_databases}
Don't show databases for which the user doesn't have any database or
table privileges. This can improve security if you're concerned about
......@@ -25730,6 +25745,17 @@ flag again, the @code{SQL_MAX_JOIN_SIZE} variable will be ignored.
You can set a default value for this variable by starting @code{mysqld} with
@code{-O max_join_size=#}.
@item SQL_QUERY_CACHE_TYPE = [OFF | ON | DEMAND]
@item SQL_QUERY_CACHE_TYPE = [0 | 1 | 2]
The numbers are standing for the correspoding verbose option.
@multitable @columnfractions .3 .7
@item 0 or OFF @tab Cache @code{SELECT} results, but don't retrieve results from cache.
@item 1 or ON @tab Cache all @code{SELECT}'s that are not marked with @code{SQL_NO_CACHE}.
@item 2 or DEMAND @tab Cache only @code{SELECT SQL_CACHE}) queries.
@end multitable
@item SQL_SAFE_UPDATES = 0 | 1
If set to @code{1}, MySQL will abort if an @code{UPDATE} or
@code{DELETE} is attempted that doesn't use a key or @code{LIMIT} in the
......@@ -31085,7 +31111,7 @@ mysql> SELECT id,FLOOR(value/100) FROM tbl_name ORDER BY RAND();
@c help SELECT
@example
SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[HIGH_PRIORITY]
[SQL_CACHE | SQL_NO_CACHE] [HIGH_PRIORITY]
[DISTINCT | DISTINCTROW | ALL]
select_expression,...
[INTO @{OUTFILE | DUMPFILE@} 'file_name' export_options]
......@@ -31213,9 +31239,8 @@ mysql> select user,max(salary) AS sum from users
@end example
@item
@code{SQL_SMALL_RESULT}, @code{SQL_BIG_RESULT}, @code{SQL_BUFFER_RESULT},
@code{STRAIGHT_JOIN}, and @code{HIGH_PRIORITY} are MySQL extensions
to ANSI SQL92.
All options beginning with @code{SQL_}, @code{STRAIGHT_JOIN}, and
@code{HIGH_PRIORITY} are MySQL extensions to ANSI SQL.
@item
@code{HIGH_PRIORITY} will give the @code{SELECT} higher priority than
......@@ -31243,6 +31268,14 @@ result set will be small. In this case, MySQL will use fast
temporary tables to store the resulting table instead of using sorting. In
MySQL Version 3.23 this shouldn't normally be needed.
@item
@code{SQL_CACHE} tells MySQL to store the query result in the query cache
even if you are using @code{SQL_QUERY_CACHE_METHOD} 2 (= @code{DEMAND}).
@item
@code{SQL_NO_CACHE} tells MySL to not store the query result in the
query cache.
@item
@cindex @code{GROUP BY}, extensions to ANSI SQL
If you use @code{GROUP BY}, the output rows will be sorted according to the
......@@ -46164,6 +46197,11 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}.
@itemize @bullet
@item
A new query cache to cache results from identical @code{SELECT} queries.
@item
Fixed core dump bug on 64 bit machines when it got a wrong communication
packet.
@item
@code{MATCH ... AGAINST(... IN BOOLEAN MODE)} can now work
without @code{FULLTEXT} index.
@item
......@@ -54,6 +54,7 @@ gptr hash_next(HASH *info,const byte *key,uint length);
my_bool hash_insert(HASH *info,const byte *data);
my_bool hash_delete(HASH *hash,byte *record);
my_bool hash_update(HASH *hash,byte *record,byte *old_key,uint old_key_length);
void hash_replace(HASH *hash, uint idx, byte *new_row);
my_bool hash_check(HASH *hash); /* Only in debug library */
#define hash_clear(H) bzero((char*) (H),sizeof(*(H)))
......
......@@ -192,7 +192,7 @@ typedef struct st_columndef /* column information */
} MI_COLUMNDEF;
/* invalidator function reference for Query Cache */
typedef void (* invalidator_by_filename) (char * filename);
typedef void (* invalidator_by_filename)(const char * filename);
extern my_string myisam_log_filename; /* Name of logfile */
extern uint myisam_block_size;
......
......@@ -94,6 +94,7 @@ inline int local_thr_alarm(my_bool *A,int B __attribute__((unused)),ALARM *C __a
#ifdef MYSQL_SERVER
extern ulong bytes_sent, bytes_received;
extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received;
extern void query_cache_insert(NET *net, const char *packet, ulong length);
#else
#undef statistic_add
#define statistic_add(A,B,C)
......@@ -108,7 +109,7 @@ static int net_write_buff(NET *net,const char *packet,ulong len);
int my_net_init(NET *net, Vio* vio)
{
if (!(net->buff=(uchar*) my_malloc(net_buffer_length+
if (!(net->buff=(uchar*) my_malloc((uint32) net_buffer_length+
NET_HEADER_SIZE + COMP_HEADER_SIZE,
MYF(MY_WME))))
return 1;
......@@ -125,6 +126,7 @@ int my_net_init(NET *net, Vio* vio)
net->compress=0; net->reading_or_writing=0;
net->where_b = net->remain_in_buf=0;
net->last_errno=0;
net->query_cache_query=0;
if (vio != 0) /* If real connection */
{
......@@ -160,7 +162,7 @@ static my_bool net_realloc(NET *net, ulong length)
pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
/* We must allocate some extra bytes for the end 0 and to be able to
read big compressed blocks */
if (!(buff=(uchar*) my_realloc((char*) net->buff, pkt_length +
if (!(buff=(uchar*) my_realloc((char*) net->buff, (uint32) pkt_length +
NET_HEADER_SIZE + COMP_HEADER_SIZE,
MYF(MY_WME))))
{
......@@ -187,7 +189,7 @@ void net_clear(NET *net)
if (!vio_is_blocking(net->vio)) /* Safety if SSL */
{
while ( (count = vio_read(net->vio, (char*) (net->buff),
net->max_packet)) > 0)
(uint32) net->max_packet)) > 0)
DBUG_PRINT("info",("skipped %d bytes from file: %s",
count,vio_description(net->vio)));
if (is_blocking)
......@@ -241,7 +243,7 @@ my_net_write(NET *net,const char *packet,ulong len)
{
const ulong z_size = MAX_THREE_BYTES;
int3store(buff, z_size);
buff[3]= net->pkt_nr++;
buff[3]= (uchar) net->pkt_nr++;
if (net_write_buff(net, (char*) buff, NET_HEADER_SIZE) ||
net_write_buff(net, packet, z_size))
return 1;
......@@ -250,7 +252,7 @@ my_net_write(NET *net,const char *packet,ulong len)
}
/* Write last packet */
int3store(buff,len);
buff[3]= net->pkt_nr++;
buff[3]= (uchar) net->pkt_nr++;
if (net_write_buff(net,(char*) buff,NET_HEADER_SIZE))
return 1;
return net_write_buff(net,packet,len);
......@@ -280,7 +282,7 @@ net_write_command(NET *net,uchar command,const char *packet,ulong len)
do
{
int3store(buff, MAX_THREE_BYTES);
buff[3]= net->pkt_nr++;
buff[3]= (uchar) net->pkt_nr++;
if (net_write_buff(net,(char*) buff, header_size) ||
net_write_buff(net,packet,len))
return 1;
......@@ -292,7 +294,7 @@ net_write_command(NET *net,uchar command,const char *packet,ulong len)
len=length; /* Data left to be written */
}
int3store(buff,length);
buff[3]= net->pkt_nr++;
buff[3]= (uchar) net->pkt_nr++;
return test(net_write_buff(net,(char*) buff,header_size) ||
net_write_buff(net,packet,len) || net_flush(net));
}
......@@ -341,6 +343,10 @@ net_real_write(NET *net,const char *packet,ulong len)
my_bool net_blocking = vio_is_blocking(net->vio);
DBUG_ENTER("net_real_write");
#ifdef MYSQL_SERVER
query_cache_insert(net, packet, len);
#endif
if (net->error == 2)
DBUG_RETURN(-1); /* socket can't be used */
......@@ -351,8 +357,8 @@ net_real_write(NET *net,const char *packet,ulong len)
ulong complen;
uchar *b;
uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE;
if (!(b=(uchar*) my_malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE,
MYF(MY_WME))))
if (!(b=(uchar*) my_malloc((uint32) len + NET_HEADER_SIZE +
COMP_HEADER_SIZE, MYF(MY_WME))))
{
#ifdef MYSQL_SERVER
net->last_errno=ER_OUT_OF_RESOURCES;
......@@ -389,7 +395,7 @@ net_real_write(NET *net,const char *packet,ulong len)
pos=(char*) packet; end=pos+len;
while (pos != end)
{
if ((long) (length=vio_write(net->vio,pos,(ulong) (end-pos))) <= 0)
if ((long) (length=vio_write(net->vio,pos,(uint32) (end-pos))) <= 0)
{
my_bool interrupted = vio_should_retry(net->vio);
#if (!defined(__WIN__) && !defined(__EMX__) && !defined(OS2))
......@@ -473,7 +479,7 @@ net_real_write(NET *net,const char *packet,ulong len)
big packet
*/
static void my_net_skip_rest(NET *net, ulong remain, thr_alarm_t *alarmed)
static void my_net_skip_rest(NET *net, uint32 remain, thr_alarm_t *alarmed)
{
ALARM alarm_buff;
uint retry_count=0;
......@@ -496,7 +502,7 @@ static void my_net_skip_rest(NET *net, ulong remain, thr_alarm_t *alarmed)
}
return;
}
remain -= length;
remain -= (uint32) length;
statistic_add(bytes_received,length,&LOCK_bytes_received);
}
}
......@@ -521,8 +527,8 @@ my_real_read(NET *net, ulong *complen)
ALARM alarm_buff;
#endif
my_bool net_blocking=vio_is_blocking(net->vio);
ulong remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
NET_HEADER_SIZE);
uint32 remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
NET_HEADER_SIZE);
*complen = 0;
net->reading_or_writing=1;
......@@ -599,7 +605,7 @@ my_real_read(NET *net, ulong *complen)
continue;
}
#endif
DBUG_PRINT("error",("Couldn't read packet: remain: %d errno: %d length: %d alarmed: %d", remain,vio_errno(net->vio),length,alarmed));
DBUG_PRINT("error",("Couldn't read packet: remain: %lu errno: %d length: %ld alarmed: %d", remain,vio_errno(net->vio),length,alarmed));
len= packet_error;
net->error=2; /* Close socket */
#ifdef MYSQL_SERVER
......@@ -608,7 +614,7 @@ my_real_read(NET *net, ulong *complen)
#endif
goto end;
}
remain -= (ulong) length;
remain -= (uint32) length;
pos+= (ulong) length;
statistic_add(bytes_received,(ulong) length,&LOCK_bytes_received);
}
......@@ -655,14 +661,14 @@ my_real_read(NET *net, ulong *complen)
{
#ifdef MYSQL_SERVER
if (i == 1)
my_net_skip_rest(net, len, &alarmed);
my_net_skip_rest(net, (uint32) len, &alarmed);
#endif
len= packet_error; /* Return error */
goto end;
}
}
pos=net->buff + net->where_b;
remain = len;
remain = (uint32) len;
}
}
......
......@@ -149,6 +149,12 @@ int mi_write(MI_INFO *info, byte *record)
info->lastpos=filepos;
myisam_log_record(MI_LOG_WRITE,info,record,filepos,0);
VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE));
if (info->invalidator != 0)
{
DBUG_PRINT("info", ("invalidator... '%s' (update)", info->filename));
(*info->invalidator)(info->filename);
info->invalidator=0;
}
allow_break(); /* Allow SIGHUP & SIGINT */
DBUG_RETURN(0);
......
......@@ -50,9 +50,10 @@ int myrg_extra(MYRG_INFO *info,enum ha_extra_function function)
void myrg_extrafunc(MYRG_INFO *info, invalidator_by_filename inv)
{
MYRG_TABLE *file;
DBUG_ENTER("myrg_extrafunc");
for (file=info->open_tables ; file != info->end_table ; file++)
file->table->s->invalidator = inv;
DBUG_VOID_RETURN;
}
......@@ -583,7 +583,8 @@ byte *hash_element(HASH *hash,uint idx)
void hash_replace(HASH *hash, uint idx, byte *new_row)
{
dynamic_element(&hash->array,idx,HASH_LINK*)->data=new_row;
if (idx != NO_RECORD) /* Safety */
dynamic_element(&hash->array,idx,HASH_LINK*)->data=new_row;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -130,7 +130,7 @@ int ha_myisam::net_read_dump(NET* net)
my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME));
for(;;)
{
uint packet_len = my_net_read(net);
ulong packet_len = my_net_read(net);
if (!packet_len)
break ; // end of file
if (packet_len == packet_error)
......@@ -139,7 +139,7 @@ int ha_myisam::net_read_dump(NET* net)
error= -1;
goto err;
}
if (my_write(data_fd, (byte*)net->read_pos, packet_len,
if (my_write(data_fd, (byte*)net->read_pos, (uint) packet_len,
MYF(MY_WME|MY_FNABP)))
{
error = errno;
......
......@@ -206,14 +206,14 @@ public:
Item_real(const char *str_arg,uint length) :value(atof(str_arg))
{
name=(char*) str_arg;
decimals=nr_of_decimals(str_arg);
decimals=(uint8) nr_of_decimals(str_arg);
max_length=length;
}
Item_real(const char *str,double val_arg,uint decimal_par,uint length)
:value(val_arg)
{
name=(char*) str;
decimals=decimal_par;
decimals=(uint8) decimal_par;
max_length=length;
}
Item_real(double value_par) :value(value_par) {}
......
This diff is collapsed.
This diff is collapsed.
......@@ -50,14 +50,14 @@ extern "C" {
int _my_b_net_read(register IO_CACHE *info, byte *Buffer,
uint Count __attribute__((unused)))
{
int read_length;
ulong read_length;
NET *net= &(current_thd)->net;
DBUG_ENTER("_my_b_net_read");
if (!info->end_of_file)
DBUG_RETURN(1); /* because my_b_get (no _) takes 1 byte at a time */
read_length=my_net_read(net);
if (read_length == (int) packet_error)
if (read_length == packet_error)
{
info->error= -1;
DBUG_RETURN(1);
......
......@@ -332,7 +332,7 @@ int mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &list,COND *conds,
ORDER *order, ORDER *group,Item *having,ORDER *proc_param,
ulong select_type,select_result *result);
int mysql_union(THD *thd,LEX *lex,select_result *result);
Field *create_tmp_field(TABLE *table,Item *item, Item::Type type,
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
Item_result_field ***copy_func, Field **from_field,
bool group,bool modify_item);
int mysql_create_table(THD *thd,const char *db, const char *table_name,
......
......@@ -3091,8 +3091,8 @@ struct show_var_st init_vars[]= {
{"record_rnd_buffer", (char*) &record_rnd_cache_size, SHOW_LONG},
{"rpl_recovery_rank", (char*) &rpl_recovery_rank, SHOW_LONG},
{"query_buffer_size", (char*) &query_buff_size, SHOW_LONG},
{"query_cache_limit", (char*) &query_cache_limit, SHOW_LONG},
{"query_cache_size", (char*) &query_cache_size, SHOW_LONG},
{"query_cache_limit", (char*) &query_cache.query_cache_limit, SHOW_LONG},
{"query_cache_size", (char*) &query_cache.query_cache_size, SHOW_LONG},
{"query_cache_startup_type",(char*) &query_cache_startup_type, SHOW_LONG},
{"safe_show_database", (char*) &opt_safe_show_db, SHOW_BOOL},
{"server_id", (char*) &server_id, SHOW_LONG},
......@@ -3157,11 +3157,11 @@ struct show_var_st status_vars[]= {
{"Open_streams", (char*) &my_stream_opened, SHOW_INT_CONST},
{"Opened_tables", (char*) &opened_tables, SHOW_LONG},
{"Questions", (char*) 0, SHOW_QUESTION},
{"Qcache_queries", (char*) &query_cache.queries_in_cache,
{"Qcache_queries_in_cache", (char*) &query_cache.queries_in_cache,
SHOW_LONG},
{"Qcache_inserts", (char*) &query_cache.inserts, SHOW_LONG},
{"Qcache_hits", (char*) &query_cache.hits, SHOW_LONG},
{"Qcache_refused", (char*) &query_cache.refused, SHOW_LONG},
{"Qcache_not_cached", (char*) &query_cache.refused, SHOW_LONG},
{"Qcache_free_memory", (char*) &query_cache.free_memory,SHOW_LONG},
{"Rpl_status", (char*) 0, SHOW_RPL_STATUS},
{"Select_full_join", (char*) &select_full_join_count, SHOW_LONG},
......@@ -3726,12 +3726,11 @@ static void get_options(int argc,char **argv)
opt_slow_log=1;
opt_slow_logname=optarg;
break;
case (int)OPT_SKIP_SLAVE_START:
case (int) OPT_SKIP_SLAVE_START:
opt_skip_slave_start = 1;
break;
case (int) OPT_SKIP_NEW:
opt_specialflag|= SPECIAL_NO_NEW_FUNC;
default_table_type=DB_TYPE_ISAM;
myisam_delay_key_write=0;
myisam_concurrent_insert=0;
myisam_recover_options= HA_RECOVER_NONE;
......@@ -3739,6 +3738,7 @@ static void get_options(int argc,char **argv)
my_use_symdir=0;
have_symlink=SHOW_OPTION_DISABLED;
ha_open_options&= ~HA_OPEN_ABORT_IF_CRASHED;
query_cache_size=0;
break;
case (int) OPT_SAFE:
opt_specialflag|= SPECIAL_SAFE_MODE;
......
......@@ -109,7 +109,7 @@ static int net_write_buff(NET *net,const char *packet,ulong len);
int my_net_init(NET *net, Vio* vio)
{
if (!(net->buff=(uchar*) my_malloc(net_buffer_length+
if (!(net->buff=(uchar*) my_malloc((uint32) net_buffer_length+
NET_HEADER_SIZE + COMP_HEADER_SIZE,
MYF(MY_WME))))
return 1;
......@@ -162,7 +162,7 @@ static my_bool net_realloc(NET *net, ulong length)
pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
/* We must allocate some extra bytes for the end 0 and to be able to
read big compressed blocks */
if (!(buff=(uchar*) my_realloc((char*) net->buff, pkt_length +
if (!(buff=(uchar*) my_realloc((char*) net->buff, (uint32) pkt_length +
NET_HEADER_SIZE + COMP_HEADER_SIZE,
MYF(MY_WME))))
{
......@@ -189,7 +189,7 @@ void net_clear(NET *net)
if (!vio_is_blocking(net->vio)) /* Safety if SSL */
{
while ( (count = vio_read(net->vio, (char*) (net->buff),
net->max_packet)) > 0)
(uint32) net->max_packet)) > 0)
DBUG_PRINT("info",("skipped %d bytes from file: %s",
count,vio_description(net->vio)));
if (is_blocking)
......@@ -243,7 +243,7 @@ my_net_write(NET *net,const char *packet,ulong len)
{
const ulong z_size = MAX_THREE_BYTES;
int3store(buff, z_size);
buff[3]= net->pkt_nr++;
buff[3]= (uchar) net->pkt_nr++;
if (net_write_buff(net, (char*) buff, NET_HEADER_SIZE) ||
net_write_buff(net, packet, z_size))
return 1;
......@@ -252,7 +252,7 @@ my_net_write(NET *net,const char *packet,ulong len)
}
/* Write last packet */
int3store(buff,len);
buff[3]= net->pkt_nr++;
buff[3]= (uchar) net->pkt_nr++;
if (net_write_buff(net,(char*) buff,NET_HEADER_SIZE))
return 1;
return net_write_buff(net,packet,len);
......@@ -282,7 +282,7 @@ net_write_command(NET *net,uchar command,const char *packet,ulong len)
do
{
int3store(buff, MAX_THREE_BYTES);
buff[3]= net->pkt_nr++;
buff[3]= (uchar) net->pkt_nr++;
if (net_write_buff(net,(char*) buff, header_size) ||
net_write_buff(net,packet,len))
return 1;
......@@ -294,7 +294,7 @@ net_write_command(NET *net,uchar command,const char *packet,ulong len)
len=length; /* Data left to be written */
}
int3store(buff,length);
buff[3]= net->pkt_nr++;
buff[3]= (uchar) net->pkt_nr++;
return test(net_write_buff(net,(char*) buff,header_size) ||
net_write_buff(net,packet,len) || net_flush(net));
}
......@@ -357,8 +357,8 @@ net_real_write(NET *net,const char *packet,ulong len)
ulong complen;
uchar *b;
uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE;
if (!(b=(uchar*) my_malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE,
MYF(MY_WME))))
if (!(b=(uchar*) my_malloc((uint32) len + NET_HEADER_SIZE +
COMP_HEADER_SIZE, MYF(MY_WME))))
{
#ifdef MYSQL_SERVER
net->last_errno=ER_OUT_OF_RESOURCES;
......@@ -395,7 +395,7 @@ net_real_write(NET *net,const char *packet,ulong len)
pos=(char*) packet; end=pos+len;
while (pos != end)
{
if ((long) (length=vio_write(net->vio,pos,(ulong) (end-pos))) <= 0)
if ((long) (length=vio_write(net->vio,pos,(uint32) (end-pos))) <= 0)
{
my_bool interrupted = vio_should_retry(net->vio);
#if (!defined(__WIN__) && !defined(__EMX__) && !defined(OS2))
......@@ -479,7 +479,7 @@ net_real_write(NET *net,const char *packet,ulong len)
big packet
*/
static void my_net_skip_rest(NET *net, ulong remain, thr_alarm_t *alarmed)
static void my_net_skip_rest(NET *net, uint32 remain, thr_alarm_t *alarmed)
{
ALARM alarm_buff;
uint retry_count=0;
......@@ -502,7 +502,7 @@ static void my_net_skip_rest(NET *net, ulong remain, thr_alarm_t *alarmed)
}
return;
}
remain -= length;
remain -= (uint32) length;
statistic_add(bytes_received,length,&LOCK_bytes_received);
}
}
......@@ -527,8 +527,8 @@ my_real_read(NET *net, ulong *complen)
ALARM alarm_buff;
#endif
my_bool net_blocking=vio_is_blocking(net->vio);
ulong remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
NET_HEADER_SIZE);
uint32 remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
NET_HEADER_SIZE);
*complen = 0;
net->reading_or_writing=1;
......@@ -605,7 +605,7 @@ my_real_read(NET *net, ulong *complen)
continue;
}
#endif
DBUG_PRINT("error",("Couldn't read packet: remain: %d errno: %d length: %d alarmed: %d", remain,vio_errno(net->vio),length,alarmed));
DBUG_PRINT("error",("Couldn't read packet: remain: %lu errno: %d length: %ld alarmed: %d", remain,vio_errno(net->vio),length,alarmed));
len= packet_error;
net->error=2; /* Close socket */
#ifdef MYSQL_SERVER
......@@ -614,7 +614,7 @@ my_real_read(NET *net, ulong *complen)
#endif
goto end;
}
remain -= (ulong) length;
remain -= (uint32) length;
pos+= (ulong) length;
statistic_add(bytes_received,(ulong) length,&LOCK_bytes_received);
}
......@@ -661,14 +661,14 @@ my_real_read(NET *net, ulong *complen)
{
#ifdef MYSQL_SERVER
if (i == 1)
my_net_skip_rest(net, len, &alarmed);
my_net_skip_rest(net, (uint32) len, &alarmed);
#endif
len= packet_error; /* Return error */
goto end;
}
}
pos=net->buff + net->where_b;
remain = len;
remain = (uint32) len;
}
}
......
......@@ -48,9 +48,9 @@ class QUICK_RANGE :public Sql_alloc {
uint flag_arg)
: min_key((char*) sql_memdup(min_key_arg,min_length_arg+1)),
max_key((char*) sql_memdup(max_key_arg,max_length_arg+1)),
min_length(min_length_arg),
max_length(max_length_arg),
flag(flag_arg)
min_length((uint16) min_length_arg),
max_length((uint16) max_length_arg),
flag((uint16) flag_arg)
{}
};
......
This diff is collapsed.
This diff is collapsed.
......@@ -236,35 +236,35 @@ class delayed_insert;
class THD :public ilink {
public:
NET net;
LEX lex;
MEM_ROOT mem_root;
HASH user_vars;
String packet; /* Room for 1 row */
struct sockaddr_in remote;
struct rand_struct rand;
char *query,*thread_stack;
char *host,*user,*priv_user,*db,*ip;
const char *proc_info, *host_or_ip;
uint client_capabilities,sql_mode,max_packet_length;
uint master_access,db_access;
TABLE *open_tables,*temporary_tables, *handler_tables;
NET net;
LEX lex;
MEM_ROOT mem_root;
HASH user_vars;
String packet; /* Room for 1 row */
struct sockaddr_in remote;
struct rand_struct rand;
char *query,*thread_stack;
char *host,*user,*priv_user,*db,*ip;
const char *proc_info, *host_or_ip;
uint client_capabilities,sql_mode,max_packet_length;
uint master_access,db_access;
TABLE *open_tables,*temporary_tables, *handler_tables;
MYSQL_LOCK *lock,*locked_tables;
ULL *ull;
ULL *ull;
struct st_my_thread_var *mysys_var;
enum enum_server_command command;
uint32 server_id;
uint32 log_seq;
uint32 file_id; // for LOAD DATA INFILE
uint32 server_id;
uint32 log_seq;
uint32 file_id; // for LOAD DATA INFILE
const char *where;
time_t start_time,time_after_lock,user_time;
time_t connect_time,thr_create_time; // track down slow pthread_create
time_t start_time,time_after_lock,user_time;
time_t connect_time,thr_create_time; // track down slow pthread_create
thr_lock_type update_lock_default;
delayed_insert *di;
struct st_transactions {
IO_CACHE trans_log;
THD_TRANS all; /* Trans since BEGIN WORK */
THD_TRANS stmt; /* Trans for current statement */
THD_TRANS all; // Trans since BEGIN WORK
THD_TRANS stmt; // Trans for current statement
uint bdb_lock_count;
} transaction;
Item *free_list, *handler_items;
......@@ -277,17 +277,20 @@ public:
Vio* active_vio;
pthread_mutex_t active_vio_lock;
#endif
ulonglong next_insert_id,last_insert_id,current_insert_id, limit_found_rows;
ha_rows select_limit,offset_limit,default_select_limit,cuted_fields,
max_join_size, sent_row_count, examined_row_count;
table_map used_tables;
ulong query_id,version, inactive_timeout,options,thread_id;
long dbug_thread_id;
ulonglong next_insert_id,last_insert_id,current_insert_id,
limit_found_rows;
ha_rows select_limit,offset_limit,default_select_limit,cuted_fields,
max_join_size, sent_row_count, examined_row_count;
table_map used_tables;
ulong query_id,version, inactive_timeout,options,thread_id;
long dbug_thread_id;
pthread_t real_id;
uint current_tablenr,tmp_table,cond_count,col_access,query_length;
uint server_status,open_options;
uint current_tablenr,tmp_table,cond_count,col_access;
uint server_status,open_options;
uint32 query_length;
enum_tx_isolation tx_isolation, session_tx_isolation;
char scramble[9];
uint8 query_cache_type; // type of query cache processing
bool slave_thread;
bool set_query_id,locked,count_cuted_fields,some_tables_deleted;
bool no_errors, allow_sum_func, password, fatal_error;
......@@ -296,18 +299,18 @@ public:
bool query_error, bootstrap, cleanup_done;
bool safe_to_cache_query;
bool volatile killed;
//type of query cache processing
byte query_cache_type;
/*
If we do a purge of binary logs, log index info of the threads
that are currently reading it needs to be adjusted. To do that
each thread that is using LOG_INFO needs to adjust the pointer to it
*/
LOG_INFO* current_linfo;
// if we do a purge of binary logs, log index info of the threads
// that are currently reading it needs to be adjusted. To do that
// each thread that is using LOG_INFO needs to adjust the pointer to it
ulong slave_proxy_id; // in slave thread we need to know in behalf of which
// thread the query is being run to replicate temp tables properly
NET* slave_net; // network connection from slave to master
/*
In slave thread we need to know in behalf of which
thread the query is being run to replicate temp tables properly
*/
ulong slave_proxy_id;
NET* slave_net; // network connection from slave -> m.
THD();
~THD();
void cleanup(void);
......
......@@ -739,9 +739,9 @@ TABLE *delayed_insert::get_local_table(THD* client_thd)
}
client_thd->proc_info="allocating local table";
copy= (TABLE*) sql_alloc(sizeof(*copy)+
(table->fields+1)*sizeof(Field**)+
table->reclength);
copy= (TABLE*) client_thd->alloc(sizeof(*copy)+
(table->fields+1)*sizeof(Field**)+
table->reclength);
if (!copy)
goto error;
*copy= *table;
......@@ -759,7 +759,7 @@ TABLE *delayed_insert::get_local_table(THD* client_thd)
found_next_number_field=table->found_next_number_field;
for (org_field=table->field ; *org_field ; org_field++,field++)
{
if (!(*field= (*org_field)->new_field(copy)))
if (!(*field= (*org_field)->new_field(&client_thd->mem_root,copy)))
return 0;
(*field)->move_field(adjust_ptrs); // Point at copy->record[0]
if (*org_field == found_next_number_field)
......
This diff is collapsed.
......@@ -47,7 +47,8 @@ static void find_best(JOIN *join,table_map rest_tables,uint index,
static uint cache_record_length(JOIN *join,uint index);
static double prev_record_reads(JOIN *join,table_map found_ref);
static bool get_best_combination(JOIN *join);
static store_key *get_store_key(KEYUSE *keyuse, table_map used_tables,
static store_key *get_store_key(THD *thd,
KEYUSE *keyuse, table_map used_tables,
KEY_PART_INFO *key_part, char *key_buff,
uint maybe_null);
static bool make_simple_join(JOIN *join,TABLE *tmp_table);
......@@ -795,7 +796,7 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
(procedure && (procedure->flags & PROC_GROUP)))
{
alloc_group_fields(&join,group);
setup_copy_fields(&join.tmp_table_param,all_fields);
setup_copy_fields(thd, &join.tmp_table_param,all_fields);
if (make_sum_func_list(&join,all_fields) || thd->fatal_error)
goto err; /* purecov: inspected */
}
......@@ -2152,7 +2153,8 @@ get_best_combination(JOIN *join)
if (!keyuse->used_tables &&
!(join->select_options & SELECT_DESCRIBE))
{ // Compare against constant
store_key_item *tmp=new store_key_item(keyinfo->key_part[i].field,
store_key_item *tmp=new store_key_item(thd,
keyinfo->key_part[i].field,
(char*)key_buff +
maybe_null,
maybe_null ?
......@@ -2166,7 +2168,8 @@ get_best_combination(JOIN *join)
tmp->copy();
}
else
*ref_key++= get_store_key(keyuse,join->const_table_map,
*ref_key++= get_store_key(join->thd,
keyuse,join->const_table_map,
&keyinfo->key_part[i],
(char*) key_buff,maybe_null);
key_buff+=keyinfo->key_part[i].store_length;
......@@ -2208,25 +2211,28 @@ get_best_combination(JOIN *join)
static store_key *
get_store_key(KEYUSE *keyuse, table_map used_tables, KEY_PART_INFO *key_part,
char *key_buff, uint maybe_null)
get_store_key(THD *thd, KEYUSE *keyuse, table_map used_tables,
KEY_PART_INFO *key_part, char *key_buff, uint maybe_null)
{
if (!((~used_tables) & keyuse->used_tables)) // if const item
{
return new store_key_const_item(key_part->field,
return new store_key_const_item(thd,
key_part->field,
key_buff + maybe_null,
maybe_null ? key_buff : 0,
key_part->length,
keyuse->val);
}
else if (keyuse->val->type() == Item::FIELD_ITEM)
return new store_key_field(key_part->field,
return new store_key_field(thd,
key_part->field,
key_buff + maybe_null,
maybe_null ? key_buff : 0,
key_part->length,
((Item_field*) keyuse->val)->field,
keyuse->val->full_name());
return new store_key_item(key_part->field,
return new store_key_item(thd,
key_part->field,
key_buff + maybe_null,
maybe_null ? key_buff : 0,
key_part->length,
......@@ -3272,7 +3278,7 @@ const_expression_in_where(COND *cond, Item *comp_item, Item **const_item)
** for send_fields
****************************************************************************/
Field *create_tmp_field(TABLE *table,Item *item, Item::Type type,
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
Item_result_field ***copy_func, Field **from_field,
bool group, bool modify_item)
{
......@@ -3314,7 +3320,7 @@ Field *create_tmp_field(TABLE *table,Item *item, Item::Type type,
item->name,table,item->binary);
}
}
current_thd->fatal_error=1;
thd->fatal_error=1;
return 0; // Error
}
case Item::FIELD_ITEM:
......@@ -3322,7 +3328,8 @@ Field *create_tmp_field(TABLE *table,Item *item, Item::Type type,
Field *org_field=((Item_field*) item)->field,*new_field;
*from_field=org_field;
if ((new_field= org_field->new_field(table))) // Should always be true
// The following should always be true
if ((new_field= org_field->new_field(&thd->mem_root,table)))
{
if (modify_item)
((Item_field*) item)->result_field= new_field;
......@@ -3510,8 +3517,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
if (!arg->const_item())
{
Field *new_field=
create_tmp_field(table,arg,arg->type(),&copy_func,tmp_from_field,
group != 0,not_all_columns);
create_tmp_field(thd, table,arg,arg->type(),&copy_func,
tmp_from_field, group != 0,not_all_columns);
if (!new_field)
goto err; // Should be OOM
tmp_from_field++;
......@@ -3527,7 +3534,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
}
else
{
Field *new_field=create_tmp_field(table,item,type,&copy_func,
Field *new_field=create_tmp_field(thd, table, item,type, &copy_func,
tmp_from_field, group != 0,
not_all_columns);
if (!new_field)
......@@ -3708,7 +3715,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
if (!using_unique_constraint)
{
group->buff=(char*) group_buff;
if (!(group->field=field->new_field(table)))
if (!(group->field=field->new_field(&thd->mem_root,table)))
goto err; /* purecov: inspected */
if (maybe_null)
{
......@@ -6410,7 +6417,7 @@ test_if_group_changed(List<Item_buff> &list)
*/
bool
setup_copy_fields(TMP_TABLE_PARAM *param,List<Item> &fields)
setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields)
{
Item *pos;
List_iterator<Item> li(fields);
......@@ -6438,7 +6445,7 @@ setup_copy_fields(TMP_TABLE_PARAM *param,List<Item> &fields)
/* set up save buffer and change result_field to point at saved value */
Field *field= item->field;
item->result_field=field->new_field(field->table);
item->result_field=field->new_field(&thd->mem_root,field->table);
char *tmp=(char*) sql_alloc(field->pack_length()+1);
if (!tmp)
goto err;
......
......@@ -190,7 +190,7 @@ TABLE *create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
void free_tmp_table(THD *thd, TABLE *entry);
void count_field_types(TMP_TABLE_PARAM *param, List<Item> &fields,
bool reset_with_sum_func);
bool setup_copy_fields(TMP_TABLE_PARAM *param,List<Item> &fields);
bool setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,List<Item> &fields);
void copy_fields(TMP_TABLE_PARAM *param);
void copy_funcs(Item_result_field **func_ptr);
bool create_myisam_from_heap(TABLE *table, TMP_TABLE_PARAM *param, int error,
......@@ -210,7 +210,7 @@ class store_key :public Sql_alloc
char *null_ptr;
char err;
public:
store_key(Field *field_arg, char *ptr, char *null, uint length)
store_key(THD *thd, Field *field_arg, char *ptr, char *null, uint length)
:null_ptr(null),err(0)
{
if (field_arg->type() == FIELD_TYPE_BLOB)
......@@ -219,7 +219,7 @@ class store_key :public Sql_alloc
field_arg->table, field_arg->binary());
else
{
to_field=field_arg->new_field(field_arg->table);
to_field=field_arg->new_field(&thd->mem_root,field_arg->table);
if (to_field)
to_field->move_field(ptr, (uchar*) null, 1);
}
......@@ -235,9 +235,9 @@ class store_key_field: public store_key
Copy_field copy_field;
const char *field_name;
public:
store_key_field(Field *to_field_arg, char *ptr, char *null_ptr_arg,
store_key_field(THD *thd, Field *to_field_arg, char *ptr, char *null_ptr_arg,
uint length, Field *from_field, const char *name_arg)
:store_key(to_field_arg,ptr,
:store_key(thd, to_field_arg,ptr,
null_ptr_arg ? null_ptr_arg : from_field->maybe_null() ? &err
: NullS,length), field_name(name_arg)
{
......@@ -260,9 +260,9 @@ class store_key_item :public store_key
protected:
Item *item;
public:
store_key_item(Field *to_field_arg, char *ptr, char *null_ptr_arg,
store_key_item(THD *thd, Field *to_field_arg, char *ptr, char *null_ptr_arg,
uint length, Item *item_arg)
:store_key(to_field_arg,ptr,
:store_key(thd, to_field_arg,ptr,
null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
&err : NullS, length), item(item_arg)
{}
......@@ -279,10 +279,10 @@ class store_key_const_item :public store_key_item
{
bool inited;
public:
store_key_const_item(Field *to_field_arg, char *ptr,
store_key_const_item(THD *thd, Field *to_field_arg, char *ptr,
char *null_ptr_arg, uint length,
Item *item_arg)
:store_key_item(to_field_arg,ptr,
:store_key_item(thd, to_field_arg,ptr,
null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
&err : NullS, length, item_arg), inited(0)
{
......
......@@ -1054,9 +1054,8 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
thd_info->query=0;
if (tmp->query)
{
uint length=(uint) strlen(tmp->query);
if (length > max_query_length)
length=max_query_length;
/* query_length is always set before tmp->query */
uint length= min(max_query_length, tmp->query_length);
thd_info->query=(char*) thd->memdup(tmp->query,length+1);
thd_info->query[length]=0;
}
......
......@@ -704,7 +704,7 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
DBUG_RETURN(0);
}
Field *field=create_tmp_field(&tmp_table,item,item->type(),
Field *field=create_tmp_field(thd, &tmp_table, item, item->type(),
(Item_result_field***) 0, &tmp_field,0,0);
if (!field ||
!(cr_field=new create_field(field,(item->type() == Item::FIELD_ITEM ?
......
......@@ -467,7 +467,8 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
key_part->key_part_flag|= HA_PART_KEY;
if (field->type() != FIELD_TYPE_BLOB)
{ // Create a new field
field=key_part->field=field->new_field(outparam);
field=key_part->field=field->new_field(&outparam->mem_root,
outparam);
field->field_length=key_part->length;
}
}
......
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