Hi Daogang,
Thank you for the work!
Here are some issues:
1) The SET INSERT_ID=n statement is associated with the query after it,
not before, so the database of the query after the SET INSERT_ID should
be used when applying the filter rules.
2) I think that this problem probably also affects SQL thread(when some
databases are filtered out by --replication-do-db or
--replication-ignore-db options). if that's true, then this issue (SQL
thread) should also be fixed and the priority of this bug should be set
higher.
Dao-Gang.Qu@stripped wrote:
> #At file:///home/daogangq/mysql/bzrwork/bug23890/mysql-5.0-bugteam/ based on
> revid:epotemkin@stripped
>
> 2789 Dao-Gang.Qu@stripped 2009-08-18
> Bug #23894 mysqlbinlog outputs SET INSERT_ID=n statements unnecesarily with
> --database
>
> mysqlbinlog --database=bar N-bin.000003 >003bar.txt
> will output all the SET INSERT_ID=n assignments in the binary log even if the
> database argument
> 'bar' isn't mentioned in the binary log. The COMMITS isn't associated with
> database in the
> binary log, so the SET INSERT_ID=n assignments will be output in any
> situation.
>
> To fix the problem, we need record and update the using database from context.
> So that
> the SET INSERT_ID=n assignments will be output in the following two cases:
> 1. The database argument is consistent with the using database.
> 2. The database argument is NULL.
> @ client/mysqlbinlog.cc
> Added database_using[] array to record and update the using database from
> context.
>
> modified:
> client/mysqlbinlog.cc
> === modified file 'client/mysqlbinlog.cc'
> --- a/client/mysqlbinlog.cc 2009-06-29 13:17:01 +0000
> +++ b/client/mysqlbinlog.cc 2009-08-18 14:59:04 +0000
> @@ -42,9 +42,11 @@
>
>
> #define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG |
> CLIENT_LOCAL_FILES)
> +#define DATABASE_NAME_LENGTH 256
>
> char server_version[SERVER_VERSION_LENGTH];
> ulong server_id = 0;
> +char database_using[DATABASE_NAME_LENGTH];
>
> // needed by net_serv.c
> ulong bytes_sent = 0L, bytes_received = 0L;
> @@ -557,6 +559,8 @@ int process_event(PRINT_EVENT_INFO *prin
>
> switch (ev_type) {
> case QUERY_EVENT:
> + /* Update the using database name */
> + strcpy(database_using, ((Query_log_event*)ev)->db);
> if (check_database(((Query_log_event*)ev)->db))
> goto end;
> ev->print(result_file, print_event_info);
> @@ -662,6 +666,15 @@ Create_file event for file_id: %u\n",exv
> Begin_load_query event for file_id: %u\n", exlq->file_id);
> break;
> }
> + case INTVAR_EVENT:
> + {
> + /* If the database argument is not NULL and inconsistent with
> + the using database, go to end. Else, print the event info */
> + if (check_database(database_using))
> + goto end;
> + ev->print(result_file, print_event_info);
> + break;
> + }
> default:
> ev->print(result_file, print_event_info);
> }
>