mariadb/sql
unknown 4b36c1d8ff Bug #16458: Simple SELECT FOR UPDATE causes "Result Set not updatable" error
'SELECT DISTINCT a,b FROM t1' should not use temp table if there is unique 
index (or primary key) on a.
There are a number of other similar cases that can be calculated without the
use of a temp table : multi-part unique indexes, primary keys or using GROUP BY 
instead of DISTINCT.
When a GROUP BY/DISTINCT clause contains all key parts of a unique
index, then it is guaranteed that the fields of the clause will be
unique, therefore we can optimize away GROUP BY/DISTINCT altogether.
This optimization has two effects:
* there is no need to create a temporary table to compute the
   GROUP/DISTINCT operation (or the temporary table will be smaller if only GROUP 
   is removed and DISTINCT stays or if DISTINCT is removed and GROUP BY stays)
* this causes the statement in effect to become updatable in Connector/Java
because the result set columns will be direct reference to the primary key of 
the table (instead to the temporary table that it currently references). 

Implemented a check that will optimize away GROUP BY/DISTINCT for queries like 
the above.
Currently it will work only for single non-constant table in the FROM clause.


mysql-test/r/distinct.result:
  Bug #16458: Simple SELECT FOR UPDATE causes "Result Set not updatable" error
    - test case
mysql-test/t/distinct.test:
  Bug #16458: Simple SELECT FOR UPDATE causes "Result Set not updatable" error
    - test case
sql/sql_select.cc:
  Bug #16458: Simple SELECT FOR UPDATE causes "Result Set not updatable" error
    - disable GROUP BY if contains the fields of a unique index.
2006-06-27 17:40:19 +03:00
..
examples Fix for bug #15558: truncate doesn't clear table on archive storage engine tables. 2006-05-18 17:10:58 +05:00
share Fixed bug #17873: confusing error message when IGNORE/USE/FORCE INDEX 2006-05-30 00:08:58 -07:00
.cvsignore
add_errmsg
client_settings.h
custom_conf.h
derror.cc
des_key_file.cc Many files: 2005-09-30 14:03:55 +02:00
discover.cc WL1424 Multiple MySQL Servers: SHOW TABLES etc. should detect new and delete old tables. 2004-09-13 14:46:38 +02:00
field.cc Fixed bug #14896. 2006-06-22 00:29:04 +04:00
field.h A fix and a test case for Bug#13134 "Length of VARCHAR() utf8 2006-02-21 19:52:20 +03:00
field_conv.cc a fix (bug #7589: Decimal types are ignored when updating data from another column). 2005-09-21 14:32:19 +05:00
filesort.cc Review fixes since last pull 2005-09-12 18:48:17 +03:00
frm_crypt.cc
gen_lex_hash.cc Merge with 4.0 2004-09-01 04:12:09 +03:00
gstream.cc
gstream.h
ha_berkeley.cc BUG#6554 Problem Building MySql on Fedora Core 3 2006-01-16 12:17:30 +01:00
ha_berkeley.h BUG#10241 cygwin port: invalid pragma interface directives 2005-05-04 15:05:56 +02:00
ha_blackhole.cc ha_blackhole.cc: 2005-08-30 02:46:03 +02:00
ha_blackhole.h ha_blackhole changes, same patch as http://lists.mysql.com/internals/27878, per brian 2005-08-26 02:09:56 +02:00
ha_heap.cc Cleanup during review of new pushed code 2006-03-30 03:11:37 +03:00
ha_heap.h Bug #12796: Record lost in HEAP table 2005-11-08 00:26:37 -05:00
ha_innodb.cc Applied innodb-4.1-ss29 snapshot. 2006-05-15 17:25:37 +04:00
ha_innodb.h BUG#10241 cygwin port: invalid pragma interface directives 2005-05-04 15:05:56 +02:00
ha_isam.cc a compiler must see '#pragma implementation' *before* 2005-06-05 19:38:52 +02:00
ha_isam.h BUG#10241 cygwin port: invalid pragma interface directives 2005-05-04 15:05:56 +02:00
ha_isammrg.cc a compiler must see '#pragma implementation' *before* 2005-06-05 19:38:52 +02:00
ha_isammrg.h BUG#10241 cygwin port: invalid pragma interface directives 2005-05-04 15:05:56 +02:00
ha_myisam.cc BUG#9622, stage 2, work together with fix for BUG#12232: 2005-10-21 06:29:17 +04:00
ha_myisam.h BUG#10241 cygwin port: invalid pragma interface directives 2005-05-04 15:05:56 +02:00
ha_myisammrg.cc a compiler must see '#pragma implementation' *before* 2005-06-05 19:38:52 +02:00
ha_myisammrg.h Bug#10400 - Improperly-defined MERGE table crashes with INSERT ... ON DUPLICATE KEY UPDATE 2005-05-18 19:40:39 +02:00
ha_ndbcluster.cc Merge poseidon.ndb.mysql.com:/home/tomas/mysql-4.1 2006-06-14 20:22:43 +02:00
ha_ndbcluster.h Fix for Bug #18184 SELECT ... FOR UPDATE does not work..: implemented ha_ndblcuster::unlock_row() and explicitly lock all rows that are not being unlocked 2006-06-08 16:12:38 +02:00
handler.cc Bug #14514 Creating table with packed key fails silently 2005-11-21 12:27:58 +01:00
handler.h Bug #18864 TRUNCATE TABLE doesn't reset AUTO_INCREMENT value on ndb table 2006-06-02 07:26:45 +02:00
hash_filo.cc a compiler must see '#pragma implementation' *before* 2005-06-05 19:38:52 +02:00
hash_filo.h forgotten s/__GNUC__/USE_PRAGMA_INTERFACE/ causes compilation faliures 2005-05-27 14:15:08 +02:00
hostname.cc Fix for bug #15756: incorrect ip address matching in ACL due to use of latin1 collation. 2006-01-24 13:58:28 +04:00
init.cc
item.cc BUG#18492: mysqld reports ER_ILLEGAL_REFERENCE in --ps-protocol 2006-04-28 11:23:31 +02:00
item.h Fixed bug#16377: result of DATE/TIME functions were compared as strings which 2006-06-13 19:09:24 +04:00
item_buff.cc group_by.result, group_by.test: 2005-06-21 04:24:21 -07:00
item_cmpfunc.cc select.result: 2006-06-20 23:05:55 +04:00
item_cmpfunc.h item_cmpfunc.h, cast.result: 2006-06-15 16:39:18 +04:00
item_create.cc Merging fix for bug #9796 "Query Cache caches queries with CURRENT_USER() 2005-04-11 10:44:48 +04:00
item_create.h Making 4.1 tree compile with -ansi -pedantic 2004-12-16 16:16:28 +03:00
item_func.cc Fix for bug #6880: LAST_INSERT_ID() within a statement 2006-06-07 14:01:10 +05:00
item_func.h Merge april.(none):/home/svoj/devel/mysql/BUG16893/mysql-4.1 2006-02-07 13:49:55 +04:00
item_geofunc.cc Fix for bug #12839 (Endian support is absurd) 2005-09-21 14:35:01 +05:00
item_geofunc.h BUG#10241 cygwin port: invalid pragma interface directives 2005-05-04 15:05:56 +02:00
item_row.cc A fix and a test case for Bug#16248 "WHERE (col1,col2) IN ((?,?)) 2006-04-07 22:26:25 +04:00
item_row.h A fix and a test case for Bug#16248 "WHERE (col1,col2) IN ((?,?)) 2006-04-07 22:26:25 +04:00
item_strfunc.cc item_strfunc.cc: 2006-06-16 23:46:37 +04:00
item_strfunc.h BUG#9535 Warning for "create table t as select uuid();" 2005-12-07 15:45:31 +01:00
item_subselect.cc BUG#18492: mysqld reports ER_ILLEGAL_REFERENCE in --ps-protocol 2006-04-28 11:23:31 +02:00
item_subselect.h - a fix for Bug#11458 "Prepared statement with subselects return random 2005-07-13 17:38:55 +04:00
item_sum.cc Fixed bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries 2006-03-29 23:30:34 +04:00
item_sum.h Fixed bug#14169: type of group_concat() result changed to blob if tmp_table was 2006-04-12 23:05:38 +04:00
item_timefunc.cc Manually merged 2006-06-17 02:11:12 +04:00
item_timefunc.h Manually merged 2006-06-17 02:11:12 +04:00
item_uniq.cc a compiler must see '#pragma implementation' *before* 2005-06-05 19:38:52 +02:00
item_uniq.h Add ifdefs to control when "#pragma implementation" should be used 2005-05-26 12:09:14 +02:00
key.cc Merge 2005-03-17 10:59:25 +04:00
lex.h WL#1596 "make mysqldump --master-data --single-transaction able to do online dump of InnoDB AND report reliable 2004-11-10 17:56:45 +01:00
lex_symbol.h
lock.cc Bug#18544 - LOCK TABLES timeout causes MyISAM table corruption 2006-04-19 22:54:25 +05:00
log.cc Fix for BUG#13023: "SQL Thread is up but doesn't move forward". Details in slave.cc; 2005-10-12 13:29:55 +02:00
log_event.cc BUG#16217 fix partly backported from 5.0. It is different in mysqlbinlog part. 2006-02-10 15:12:27 +02:00
log_event.h Fix for BUG#13023: "SQL Thread is up but doesn't move forward". Details in slave.cc; 2005-10-12 13:29:55 +02:00
Makefile.am Makefile.am, configure.in: 2005-09-24 15:51:45 +02:00
matherr.c
mf_iocache.cc
my_lock.c
mysql_priv.h Merge mysql.com:/net/nb/home/elkin/MySQL/FIXES/4.1-bug19188_tmp_name 2006-05-12 21:38:41 +03:00
mysqld.cc Add comment for 'kill_server' function 2006-05-23 10:33:53 +02:00
mysqld_suffix.h New MYSQL_SERVER_SUFFIX usage (for easier compilation) 2004-05-25 02:28:44 +03:00
net_serv.cc Merge selena.:H:/MYSQL/src/#05588-mysql-4.0 2005-09-07 14:59:41 +04:00
nt_servc.cc
nt_servc.h
opt_range.cc Bug #4981: 4.x and 5.x produce non-optimal execution path, 2006-06-02 12:04:03 +03:00
opt_range.h BUG#12915: Added single-table UPDATE/DELTE ... ORDER BY ... LIMIT 2005-09-30 15:21:37 +04:00
opt_sum.cc Merge april:devel/BitKeeper/mysql-4.1 2006-06-21 17:51:16 +05:00
password.c A fix for Bug#13944 "libmysqlclient exporting sha1_result function": 2006-01-11 17:31:52 +03:00
procedure.cc a compiler must see '#pragma implementation' *before* 2005-06-05 19:38:52 +02:00
procedure.h BUG#10241 cygwin port: invalid pragma interface directives 2005-05-04 15:05:56 +02:00
protocol.cc A fix and a test case for Bug#15613 "libmysqlclient API function 2006-01-18 22:50:31 +03:00
protocol.h BUG#10241 cygwin port: invalid pragma interface directives 2005-05-04 15:05:56 +02:00
protocol_cursor.cc a compiler must see '#pragma implementation' *before* 2005-06-05 19:38:52 +02:00
records.cc Added more tests for new UPDATE ... ORDER BY ... LIMIT optimization 2005-10-25 02:27:40 +03:00
repl_failsafe.cc fix for Valgrind errors: query_id needs to be inited early (already fixed in 5.0 by Konstantin) and so does client_capabilities (not fixed in 5.0); 2005-10-14 15:34:52 +02:00
repl_failsafe.h Merge with 4.0 for 4.1 release 2004-10-06 19:14:33 +03:00
set_var.cc Merge jamppa@bk-internal.mysql.com:/home/bk/mysql-4.1 2006-04-30 16:20:26 +03:00
set_var.h A fix and a test case for Bug#16365 "Prepared Statements: DoS with 2006-04-07 23:37:06 +04:00
slave.cc fix for Valgrind errors: query_id needs to be inited early (already fixed in 5.0 by Konstantin) and so does client_capabilities (not fixed in 5.0); 2005-10-14 15:34:52 +02:00
slave.h Fix for BUG#13023: "SQL Thread is up but doesn't move forward". Details in slave.cc; 2005-10-12 13:29:55 +02:00
spatial.cc Review of new pushed code 2005-11-01 13:00:02 +02:00
spatial.h Fix for bug #14320 (MBROverlaps does wrong test) 2005-12-10 18:20:00 +04:00
sql_acl.cc Bug#16372: Server crashes when test 'conc_sys' is running 2006-04-27 14:54:36 +04:00
sql_acl.h Fix for bug #12423 "Deadlock when doing FLUSH PRIVILEGES and GRANT in 2005-09-01 16:52:59 +04:00
sql_analyse.cc Merged code. Removed unneccessary repeating. 2005-09-13 18:11:51 +03:00
sql_analyse.h Add ifdefs to control when "#pragma implementation" should be used 2005-05-26 12:09:14 +02:00
sql_base.cc Fixed bug #17873: confusing error message when IGNORE/USE/FORCE INDEX 2006-05-30 00:08:58 -07:00
sql_bitmap.h terminal.c, sql_bitmap.h, my_sys.h, configure.in, config.h: 2005-05-05 09:15:14 +02:00
sql_cache.cc A fix for Bug#7209 "Client error with "Access Denied" on updates 2006-01-04 17:35:30 +03:00
sql_cache.h Merge sanja.is.com.ua:/home/bell/mysql/bk/work-4.0 2005-09-06 12:18:23 +03:00
sql_class.cc Merge rkalimullin@bk-internal.mysql.com:/home/bk/mysql-4.1 2006-05-25 16:05:55 +05:00
sql_class.h Merge bk-internal.mysql.com:/home/bk/mysql-4.1 2006-04-07 23:50:45 +04:00
sql_client.cc
sql_crypt.cc a compiler must see '#pragma implementation' *before* 2005-06-05 19:38:52 +02:00
sql_crypt.h Add ifdefs to control when "#pragma implementation" should be used 2005-05-26 12:09:14 +02:00
sql_db.cc Bug #15302 LOAD DATA FROM MASTER -> Packets out of order (Found: 2, expected 1) 2006-01-31 12:47:22 +01:00
sql_delete.cc Bug#17137 Running "truncate table" on temporary table leaves the table open on a slave 2006-03-08 10:15:48 +01:00
sql_derived.cc fixed union types merging and table related metadata (BUG#8824) 2005-03-23 08:36:48 +02:00
sql_do.cc Fix for bug #6765 "Implicit access to time zone description 2004-12-09 13:31:46 +03:00
sql_error.cc abort storing query to query cache if warnings appeared (BUG#9414) 2005-06-28 00:52:21 +03:00
sql_handler.cc Re-run fix-fields on condition if table was reopened in HANDLERREAD 2006-01-10 19:13:12 +02:00
sql_help.cc * Added comments and one assert 2004-12-14 03:36:19 +03:00
sql_insert.cc Fix calls to free_underlaid_joins() in INSERT, DELETE, and UPDATE 2005-12-08 12:33:33 -08:00
sql_lex.cc Merge mysql.com:/data0/mysqldev/my/mysql-4.1.20-release 2006-05-26 18:31:25 +02:00
sql_lex.h Fixed bug #14927. 2006-05-06 23:48:13 -07:00
sql_list.cc a compiler must see '#pragma implementation' *before* 2005-06-05 19:38:52 +02:00
sql_list.h merged 2005-05-18 22:14:08 +02:00
sql_load.cc Bug #17154 load data infile of char values into a table of char(PK) hangs 2006-02-07 00:03:39 +01:00
sql_manager.cc
sql_manager.h
sql_map.cc a compiler must see '#pragma implementation' *before* 2005-06-05 19:38:52 +02:00
sql_map.h Add ifdefs to control when "#pragma implementation" should be used 2005-05-26 12:09:14 +02:00
sql_olap.cc a compiler must see '#pragma implementation' *before* 2005-06-05 19:38:52 +02:00
sql_parse.cc Fixed bug#19225: unchecked error results in server crash 2006-05-29 00:32:59 +04:00
sql_prepare.cc Fixed bug #14927. 2006-05-06 23:48:13 -07:00
sql_rename.cc Bug#6391 (binlog-do-db rules ignored) 2004-12-03 12:13:51 +01:00
sql_repl.cc Fix for BUG#12003 "assertion failure in testsuite (double lock of 2005-07-18 14:46:53 +02:00
sql_repl.h Remove DUP_IGNORE from enum_duplicates and instead use a separate ignore flag 2004-12-31 12:04:35 +02:00
sql_select.cc Bug #16458: Simple SELECT FOR UPDATE causes "Result Set not updatable" error 2006-06-27 17:40:19 +03:00
sql_select.h Fixed bug #18206. 2006-06-02 14:14:57 -07:00
sql_show.cc Merge jamppa@bk-internal.mysql.com:/home/bk/mysql-4.1 2006-05-04 13:17:16 +03:00
sql_sort.h
sql_state.c
sql_string.cc Bug#15375 Unassigned multibyte codes are broken 2005-12-12 21:42:09 +04:00
sql_string.h BUG#10241 cygwin port: invalid pragma interface directives 2005-05-04 15:05:56 +02:00
sql_table.cc Merge bk@192.168.21.1:mysql-4.1 2006-05-04 00:03:58 +05:00
sql_test.cc Bug#12920 - key_read_requests counter appears to re-set 2005-09-14 13:18:16 +02:00
sql_udf.cc - backport of a compile fix from 4.1 (ChangeSet@1.2260.23.2 2005/05/19 from reggie) 2005-06-30 17:33:23 +02:00
sql_udf.h Merge bk-internal.mysql.com:/home/bk/mysql-4.1 2005-05-09 12:16:59 +02:00
sql_union.cc Fixed bug #18767. 2006-04-20 22:15:38 -07:00
sql_update.cc BUG#18036 - update of table joined to self reports table as crashed 2006-06-19 14:05:14 +05:00
sql_yacc.yy Fixed bug #18767. 2006-04-20 22:15:38 -07:00
stacktrace.c Step 2 of the switch to support configuration with NPTL: 2005-04-20 20:38:57 +02:00
stacktrace.h Step 2 of the switch to support configuration with NPTL: 2005-04-20 20:38:57 +02:00
strfunc.cc - Housekeeping: removed a few unreferenced variables, noticed while doing 2005-01-11 15:38:03 +01:00
structs.h Better comments in KEY_PART_INFO struct 2006-06-14 21:06:02 +04:00
table.cc Bug#18004 Connecting crashes server when default charset is UCS2 2006-03-20 14:43:02 +04:00
table.h Merge mysql.com:/home/mydev/mysql-4.0-bug5390 2006-01-23 19:19:29 +01:00
thr_malloc.cc Simpler arena swapping code 2004-11-08 01:13:54 +02:00
time.cc Fix for bug #7297 "Two digit year should be interpreted correctly 2004-12-16 16:31:50 +03:00
tzfile.h WL#1264 "Per-thread time zone support infrastructure". 2004-06-18 10:11:31 +04:00
tztime.cc Minor Netware specific changes. 2005-12-13 18:30:10 +02:00
tztime.h BUG#10241 cygwin port: invalid pragma interface directives 2005-05-04 15:05:56 +02:00
udf_example.cc Ensure that we free memory used with --order-by-primary (in mysqldump) 2004-12-09 12:47:20 +02:00
uniques.cc
unireg.cc Review of new code: 2005-07-27 13:05:30 +03:00
unireg.h Fixed bug#14169: type of group_concat() result changed to blob if tmp_table was 2006-04-12 23:05:38 +04:00
watchdog_mysqld