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

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
Loading
Loading
Loading
Loading
+42 −4
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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)))
+1 −1
Original line number Diff line number Diff line
@@ -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;
+24 −18
Original line number Diff line number Diff line
@@ -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,7 +527,7 @@ 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 :
  uint32 remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
		  NET_HEADER_SIZE);
  *complen = 0;

@@ -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;
      }
    }

+6 −0
Original line number Diff line number Diff line
@@ -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);

Loading