Commit 48405ec7 authored by unknown's avatar unknown
Browse files

WL#1034 update

- fix EVENT_ACL problem that GRANT ALL on some_db.* to someone@somewhere did not get to mysql.db
- fix crash when the following is executed :
  CREATE EVENT P() CREATE EVENT E ON SCHEDULER 1 SECOND DO ROLLBACK;
  (creation works as well as calling P() which creates the event).


mysql-test/lib/init_db.sql:
  - fix init_db.sql so add Event_priv to the database privs, many tests failed because of that
    ommision
  - remove the quotes from the column names
mysql-test/t/events.test:
  - fix the small test, don't create own db
scripts/mysql_fix_privilege_tables.sql:
  - fix that
sql/event.cc:
  - be defensive and don't crash if outside has already has opened some table
sql/event_executor.cc:
  - show in SHOW PROCESSLIST - "event_scheduler" as name of the user of the main thread
  - use "localhost" as the host where event_scheduler comes from
  - comment out some debug info, fix other debug info
sql/event_timed.cc:
  - enable EVENT creation inside SP. sphead from lex->sphead goes to et->sphead. it's there only
    if we compile the event. OTOH when doing 
    CREATE PROCEDURE PROC() CREATE EVENT SOME_EV ON SCHEDULE EVERY 1 SECOND DO ROLLBACK;
    I have only to get the body of the event which is anonymous SP. Before it being "compiled"
    but then freed without being used because a bit later it is compiled one more time before
    being put in the events cache. So it was good that the memory structures weren't reused but
    scrapped out. Now lex->sphead is not needed during event creation but only where the event's
    body starts and where it ends so to be able at later stage to compile this anonymous SP (the
    body of the event).
sql/sp_head.cc:
  - copy over a fix to a crash
sql/sql_acl.h:
  - fix privileges.
    There was _NO_ documentation about that. Another CHUNK had to be created to so EVENT_ACL gets shifted to
    it's place in the db table. So how this is calculated? EVENT_ACL is 1 << 26. Remember 26, see which poistion
    in the db table is EVENT_ACL, it's 17, counted from 0. 26 - 17 = 9, then shift it with 9.
    CHUNKS are created because in some cases some privileges are in chunks and they are shifted at once. There are
    few chunks of such privileges which has to be shifted to get to exactly the structure of mysql.db table.
sql/sql_parse.cc:
  - ok, we don't care anymore about lex->sphead because our sphead is lex->et->sphead
sql/sql_yacc.yy:
  - bail out if new event_timed returns 0x0
  - enable creation of an event inside a SP
    CREATE PROCEDURE P() CREATE EVENT E ON SCHEDULE EVERY 1 SECOND DO SELECT 1;
parent b67555d5
Loading
Loading
Loading
Loading
+19 −18
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ CREATE TABLE db (
  Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL,
  Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL,
  Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL,
  Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL,
  PRIMARY KEY Host (Host,Db,User),
  KEY User (User)
) engine=MyISAM
@@ -29,8 +30,8 @@ CHARACTER SET utf8 COLLATE utf8_bin
comment='Database privileges';

  
INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N');
INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N');
INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N','Y');
INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N','Y');


CREATE TABLE host (
@@ -570,26 +571,26 @@ CREATE TABLE proc (


CREATE TABLE event (
  'db' VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  'name' VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  'body' longblob NOT NULL,
  'definer' VARCHAR(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  'execute_at' DATETIME default NULL,
  'transient_expression' int(11) default NULL,
  'interval_type' ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK',
  db VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  name VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  body longblob NOT NULL,
  definer VARCHAR(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  execute_at DATETIME default NULL,
  transient_expression int(11) default NULL,
  interval_type ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK',
                       'SECOND','MICROSECOND', 'YEAR_MONTH','DAY_HOUR',
                       'DAY_MINUTE','DAY_SECOND',
                       'HOUR_MINUTE','HOUR_SECOND',
                       'MINUTE_SECOND','DAY_MICROSECOND',
                       'HOUR_MICROSECOND','MINUTE_MICROSECOND',
                       'SECOND_MICROSECOND') default NULL,
  'created' TIMESTAMP NOT NULL default '0000-00-00 00:00:00',
  'modified' TIMESTAMP NOT NULL default '0000-00-00 00:00:00',
  'last_executed' DATETIME default NULL,
  'starts' DATETIME default NULL,
  'ends' DATETIME default NULL,
  'status' ENUM('ENABLED','DISABLED') NOT NULL default 'ENABLED',
  'on_completion' ENUM('DROP','PRESERVE') NOT NULL default 'DROP',
  'comment' varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  PRIMARY KEY  ('db','name')
  created TIMESTAMP NOT NULL,
  modified TIMESTAMP NOT NULL,
  last_executed DATETIME default NULL,
  starts DATETIME default NULL,
  ends DATETIME default NULL,
  status ENUM('ENABLED','DISABLED') NOT NULL default 'ENABLED',
  on_completion ENUM('DROP','PRESERVE') NOT NULL default 'DROP',
  comment varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  PRIMARY KEY  (db, name)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events';
+21 −0
Original line number Diff line number Diff line
use test;
drop event if exists event1;
Warnings:
Note	1305	Event event1 does not exist
create event event1 on schedule every 15 minute starts now() ends date_add(now(), interval 5 hour) DO begin end;
alter event event1 rename to event2;
alter event event2 disable;
drop event event2;
create event event2 on schedule every 2 second starts now() ends date_add(now(), interval 5 hour) comment "some" DO begin end;
drop event event2;
create table t_event3 (a int, b float);
drop event if exists event3;
Warnings:
Note	1305	Event event3 does not exist
create event event3 on schedule every 50 + 10 minute starts date_add("20010101", interval 5 minute) ends date_add("20151010", interval 5 day) comment "portokala_comment" DO insert into t_event3 values (unix_timestamp(), rand());
set max_allowed_packet=128000000;
select count(*) from t_event3;
count(*)
0
drop event event3;
drop table t_event3;
+2 −4
Original line number Diff line number Diff line
create database events_test;
use events_test;
use test;
drop event if exists event1;
create event event1 on schedule every 15 minute starts now() ends date_add(now(), interval 5 hour) DO begin end;
alter event event1 rename to event2;
@@ -13,7 +12,6 @@ create table t_event3 (a int, b float);
drop event if exists event3;
create event event3 on schedule every 50 + 10 minute starts date_add("20010101", interval 5 minute) ends date_add("20151010", interval 5 day) comment "portokala_comment" DO insert into t_event3 values (unix_timestamp(), rand());
set max_allowed_packet=128000000;
select sha1(space(9999999));
select count(*) from t_event3;
drop event event3;
drop database events_test;
drop table t_event3;
+3 −2
Original line number Diff line number Diff line
@@ -562,5 +562,6 @@ CREATE TABLE event (
# EVENT privilege
#

ALTER TABLE mysql.user add Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_user_priv;
ALTER TABLE mysql.db add Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL;
ALTER TABLE mysql.user add Event_priv enum('N','Y') character set utf8 DEFAULT 'N' NOT NULL AFTER Create_user_priv;
ALTER TABLE mysql.db add Event_priv enum('N','Y') character set utf8 DEFAULT 'N' NOT NULL;
+3 −0
Original line number Diff line number Diff line
@@ -652,6 +652,7 @@ evex_load_and_compile_event(THD * thd, sp_name *spn, bool use_lock)
  int ret= 0;
  MEM_ROOT *tmp_mem_root;
  event_timed *ett;
  Open_tables_state backup;

  DBUG_ENTER("db_load_and_compile_event");
  DBUG_PRINT("enter", ("name: %*s", spn->m_name.length, spn->m_name.str));
@@ -659,10 +660,12 @@ evex_load_and_compile_event(THD * thd, sp_name *spn, bool use_lock)
  tmp_mem_root= thd->mem_root;
  thd->mem_root= &evex_mem_root;

  thd->reset_n_backup_open_tables_state(&backup);
  // no need to use my_error() here because db_find_event() has done it
  if ((ret= db_find_event(thd, spn, &ett, NULL)))
    goto done;

  thd->restore_backup_open_tables_state(&backup);
  /*
    allocate on evex_mem_root. if you call without evex_mem_root
    then sphead will not be cleared!
Loading