Skip to content

Commit 788bc3f

Browse files
author
monty@hundin.mysql.fi
committed
Fixed that LOAD DATA INFILE works with transactions.
Fix for lower case filenames
1 parent b0a0c54 commit 788bc3f

File tree

9 files changed

+74
-4032
lines changed

9 files changed

+74
-4032
lines changed

Docs/manual.texi

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,18 +3730,31 @@ list in this manual. @xref{TODO}.
37303730

37313731
@cindex sub-selects
37323732

3733-
The following will not yet work in MySQL:
3733+
MySQL currently only supports sub selects of the form @code{INSERT
3734+
... SELECT ...} and @code{REPLACE ... SELECT ...}. You can however use
3735+
the function @code{IN()} in other contexts.
3736+
3737+
In many cases you can rewrite the query without a sub-select:
37343738

37353739
@example
37363740
SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
3741+
@end example
3742+
3743+
This can be re-written as:
3744+
3745+
@example
3746+
SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
3747+
@end example
3748+
3749+
The queries:
3750+
@example
37373751
SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
37383752
SELECT * FROM table1 WHERE NOT EXISTS (SELECT id FROM table2 where table1.id=table2.id);
37393753
@end example
37403754

3741-
However, in many cases you can rewrite the query without a sub-select:
3755+
Can be rewritten as:
37423756

37433757
@example
3744-
SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
37453758
SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id IS NULL
37463759
@end example
37473760

@@ -3777,11 +3790,9 @@ second instance of the interpreter:
37773790
prompt> mysql --skip-column-names mydb < myscript.sql | mysql mydb
37783791
@end example
37793792

3780-
MySQL only supports @code{INSERT ... SELECT ...} and
3781-
@code{REPLACE ... SELECT ...} Independent sub-selects will probably
3782-
be available in Version 4.0. You can now use the function @code{IN()} in
3783-
other contexts, however.
3784-
3793+
MySQL 4.0 supports multi-table deletes that can be used to efficiently
3794+
delete rows based on information from one table or even from many tables
3795+
at the same time.
37853796

37863797
@node Missing SELECT INTO TABLE, Missing Transactions, Missing Sub-selects, Missing functions
37873798
@subsubsection @code{SELECT INTO TABLE}

bdb/lock/lock_region.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ __lock_init(dbenv, lt)
291291
sizeof(struct __db_lock), MUTEX_ALIGN, &lp)) != 0)
292292
goto mem_err;
293293
lp->status = DB_LSTAT_FREE;
294+
lp->gen=0;
294295
if ((ret = __db_shmutex_init(dbenv, &lp->mutex,
295296
R_OFFSET(&lt->reginfo, &lp->mutex) + DB_FCNTL_OFF_LOCK,
296297
MUTEX_SELF_BLOCK, &lt->reginfo,

mysql-test/misc/select.tst

Lines changed: 0 additions & 4015 deletions
This file was deleted.

mysql-test/r/gemini.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,9 @@ _userid
362362
marc@anyware.co.uk
363363
_userid
364364
marc@anyware.co.uk
365+
f1
366+
65
367+
379
368+
468
369+
469
370+
508

mysql-test/std_data/gemini.dat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
65,-1,1
2+
379,-1,1
3+
468,-1,1
4+
469,-1,1
5+
508,-1,1

mysql-test/t/gemini.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,18 @@ SELECT * FROM t1;
338338
SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
339339
drop table t1;
340340
set autocommit=1;
341+
342+
#
343+
# Test of load data infile
344+
#
345+
346+
CREATE TABLE if not exists `t1` (
347+
`f1` int(11) unsigned NOT NULL default '0',
348+
`f2` tinyint(3) unsigned NOT NULL default '0',
349+
`f3` tinyint(3) unsigned NOT NULL default '0',
350+
PRIMARY KEY (`f1`)
351+
) TYPE=Gemini;
352+
lock table t1 write;
353+
load data infile ''../../std_data/gemini.dat' ignore into table t1 fields terminated by ',';
354+
select f1 from t1;
355+
drop table t1;

sql/sql_load.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
7171
String *field_term=ex->field_term,*escaped=ex->escaped,
7272
*enclosed=ex->enclosed;
7373
bool is_fifo=0;
74+
bool using_transactions;
75+
7476
DBUG_ENTER("mysql_load");
7577

7678
if (escaped->length() > 1 || enclosed->length() > 1)
@@ -239,16 +241,21 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
239241
free_blobs(table); /* if pack_blob was used */
240242
table->copy_blobs=0;
241243
thd->count_cuted_fields=0; /* Don`t calc cuted fields */
244+
using_transactions = table->file->has_transactions();
242245
if (error)
243-
DBUG_RETURN(-1); // Error on read
246+
{
247+
if (using_transactions)
248+
ha_autocommit_or_rollback(thd,error);
249+
DBUG_RETURN(-1); // Error on read
250+
}
244251
sprintf(name,ER(ER_LOAD_INFO),info.records,info.deleted,
245252
info.records-info.copied,thd->cuted_fields);
246253
send_ok(&thd->net,info.copied+info.deleted,0L,name);
247254
// on the slave thd->query is never initialized
248255
if(!thd->slave_thread)
249256
mysql_update_log.write(thd,thd->query,thd->query_length);
250257

251-
if (!table->file->has_transactions())
258+
if (!using_transactions)
252259
thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
253260
if (!read_file_from_client && mysql_bin_log.is_open())
254261
{
@@ -257,7 +264,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
257264
handle_duplicates);
258265
mysql_bin_log.write(&qinfo);
259266
}
260-
DBUG_RETURN(0);
267+
if (using_transactions)
268+
error=ha_autocommit_or_rollback(thd,error);
269+
DBUG_RETURN(error);
261270
}
262271

263272

sql/sql_show.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
182182
TABLE_LIST table_list;
183183
DBUG_ENTER("mysql_find_files");
184184

185+
if (wild && !wild[0])
186+
wild=0;
185187
bzero((char*) &table_list,sizeof(table_list));
186188

187189
if (!(dirp = my_dir(path,MYF(MY_WME | (dir ? MY_WANT_STAT : 0)))))
@@ -200,7 +202,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
200202
#endif
201203
{
202204
if (file->name[0] == '.' || !MY_S_ISDIR(file->mystat.st_mode) ||
203-
(wild && wild[0] && wild_compare(file->name,wild)))
205+
(wild && wild_compare(file->name,wild)))
204206
continue;
205207
}
206208
}
@@ -211,8 +213,16 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
211213
is_prefix(file->name,tmp_file_prefix))
212214
continue;
213215
*ext=0;
214-
if (wild && wild[0] && wild_compare(file->name,wild))
215-
continue;
216+
if (wild)
217+
{
218+
if (lower_case_table_names)
219+
{
220+
if (wild_case_compare(file->name,wild))
221+
continue;
222+
}
223+
else if (wild_compare(file->name,wild))
224+
continue;
225+
}
216226
}
217227
/* Don't show tables where we don't have any privileges */
218228
if (db && !(col_access & TABLE_ACLS))

sql/sql_string.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ String *copy_if_not_alloced(String *to,String *from,uint32 from_length)
542542
#endif
543543

544544
int wild_case_compare(const char *str,const char *str_end,
545-
const char *wildstr,const char *wildend,
546-
char escape)
545+
const char *wildstr,const char *wildend,
546+
char escape)
547547
{
548548
int result= -1; // Not found, using wildcards
549549
#ifdef USE_MB
@@ -677,7 +677,7 @@ int wild_case_compare(String &match,String &wild, char escape)
677677
*/
678678

679679
int wild_compare(const char *str,const char *str_end,
680-
const char *wildstr,const char *wildend,char escape)
680+
const char *wildstr,const char *wildend,char escape)
681681
{
682682
int result= -1; // Not found, using wildcards
683683
while (wildstr != wildend)

0 commit comments

Comments
 (0)