summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@hundin.mysql.fi>2001-12-23 02:44:28 +0200
committerunknown <monty@hundin.mysql.fi>2001-12-23 02:44:28 +0200
commitb5f59804979975140142b60e21dc4ac08dfdb66a (patch)
tree26c5c120f95a5455d1d2b6d0fc13c94e3639705e /sql
parent6ad422802bf9cdf67e5155be1d8143fee0d659ad (diff)
parent953ac1a5cf2acc464c3214e715679e61c4d18c24 (diff)
downloadmariadb-git-b5f59804979975140142b60e21dc4ac08dfdb66a.tar.gz
Merge work:/home/bk/mysql-4.0 into hundin.mysql.fi:/my/bk/mysql-4.0
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_cache.cc39
-rw-r--r--sql/sql_parse.cc21
-rw-r--r--sql/sql_table.cc5
3 files changed, 36 insertions, 29 deletions
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 399f0dda04e..523e835f472 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -743,7 +743,7 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
/* Key is query + database + flag */
if (thd->db_length)
{
- memcpy(thd->query+thd->query_length, thd->db, thd->db_length);
+ memcpy(thd->query+thd->query_length+1, thd->db, thd->db_length);
DBUG_PRINT("qcache", ("database : %s length %u",
thd->db, thd->db_length));
}
@@ -761,7 +761,7 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
flags|= (byte) thd->convert_set->number();
DBUG_ASSERT(thd->convert_set->number() < 128);
}
- tot_length=thd->query_length+1+thd->db_length;
+ tot_length=thd->query_length+thd->db_length+2;
thd->query[tot_length-1] = (char) flags;
/* Check if another thread is processing the same query? */
@@ -832,7 +832,6 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
statistic_increment(refused, &structure_guard_mutex);
end:
- thd->query[thd->query_length]= 0; // Restore end null
DBUG_VOID_RETURN;
}
@@ -890,12 +889,10 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
goto err;
}
- /* Test if the query is a SELECT */
- while (*sql == ' ' || *sql == '\t')
- {
- sql++;
- query_length--;
- }
+ /*
+ Test if the query is a SELECT
+ (pre-space is removed in dispatch_command)
+ */
if (toupper(sql[0]) != 'S' || toupper(sql[1]) != 'E' ||
toupper(sql[2]) !='L')
{
@@ -911,10 +908,10 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
}
Query_cache_block *query_block;
- tot_length=query_length+thd->db_length+1;
+ tot_length=query_length+thd->db_length+2;
if (thd->db_length)
{
- memcpy(sql+query_length, thd->db, thd->db_length);
+ memcpy(sql+query_length+1, thd->db, thd->db_length);
DBUG_PRINT("qcache", ("database: '%s' length %u",
thd->db, thd->db_length));
}
@@ -936,9 +933,6 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
sql[tot_length-1] = (char) flags;
query_block = (Query_cache_block *) hash_search(&queries, (byte*) sql,
tot_length);
-
- sql[query_length] = '\0'; // Restore end null
-
/* Quick abort on unlocked data */
if (query_block == 0 ||
query_block->query()->result() == 0 ||
@@ -2582,8 +2576,11 @@ my_bool Query_cache::move_by_type(byte **border,
pthread_cond_init(&new_query->lock, NULL);
pthread_mutex_init(&new_query->clients_guard,MY_MUTEX_INIT_FAST);
+ /*
+ If someone is writing to this block, inform the writer that the block
+ has been moved.
+ */
NET *net = new_block->query()->writer();
- /* QQ: When could this happen ? */
if (net != 0)
{
net->query_cache_query= (gptr) new_block;
@@ -2877,15 +2874,17 @@ void Query_cache::queries_dump()
{
uint len;
char *str = (char*) query_cache_query_get_key((byte*) block, &len, 0);
- uint flags = (uint) (uchar) str[len-1];
- DBUG_PRINT("qcache", ("%u (%u,%u) %.*s",len,
+ len--; // Point at flags
+ uint flags = (uint) (uchar) str[len];
+ str[len]=0;
+ DBUG_PRINT("qcache", ("%u (%u,%u) '%s' '%s'",
((flags & QUERY_CACHE_CLIENT_LONG_FLAG_MASK)? 1:0),
- (flags & QUERY_CACHE_CHARSET_CONVERT_MASK), len-1,
- str));
+ (flags & QUERY_CACHE_CHARSET_CONVERT_MASK), len,
+ str,strend(str)+1));
DBUG_PRINT("qcache", ("-b- 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx", (ulong) block,
(ulong) block->next, (ulong) block->prev,
(ulong)block->pnext, (ulong)block->pprev));
-
+ str[len]=(char) flags;
for (TABLE_COUNTER_TYPE t = 0; t < block->n_tables; t++)
{
Query_cache_table *table = block->table(t)->parent;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index af6bd07cdc5..3662aa301e2 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -840,25 +840,32 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
case COM_QUERY:
{
- char *pos=packet-1+packet_length; // Point at end null
- /* Remove garage at end of query */
+ packet_length--; // Remove end null
+ /* Remove garage at start and end of query */
+ while (isspace(packet[0]) && packet_length > 0)
+ {
+ packet++;
+ packet_length--;
+ }
+ char *pos=packet+packet_length; // Point at end null
while (packet_length > 0 && (pos[-1] == ';' || isspace(pos[-1])))
{
pos--;
packet_length--;
}
- thd->query_length= packet_length;
+ /* We must allocate some extra memory for query cache */
if (!(thd->query= (char*) thd->memdup_w_gap((gptr) (packet),
- packet_length+1,
- thd->db_length+1)))
+ packet_length,
+ thd->db_length+2)))
break;
thd->query[packet_length]=0;
thd->packet.shrink(net_buffer_length); // Reclaim some memory
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),QUERY_PRIOR);
mysql_log.write(thd,command,"%s",thd->query);
- DBUG_PRINT("query",("%s",thd->query));
- mysql_parse(thd,thd->query,packet_length-1);
+ DBUG_PRINT("query",("'%s'",thd->query));
+ /* thd->query_length is set by mysql_parse() */
+ mysql_parse(thd,thd->query,packet_length);
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),WAIT_PRIOR);
DBUG_PRINT("info",("query ready"));
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index d3c11ab8716..6ded046ccbf 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -558,9 +558,10 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
}
}
key_info->key_length=(uint16) key_length;
- if (key_length > file->max_key_length() && key->type != Key::FULLTEXT)
+ uint max_key_length= max(file->max_key_length(), MAX_KEY_LENGTH);
+ if (key_length > max_key_length && key->type != Key::FULLTEXT)
{
- my_error(ER_TOO_LONG_KEY,MYF(0),file->max_key_length());
+ my_error(ER_TOO_LONG_KEY,MYF(0),max_key_length);
DBUG_RETURN(-1);
}
}