1
- /* Copyright (c) 2014, 2016 , Oracle and/or its affiliates. All rights reserved.
1
+ /* Copyright (c) 2014, 2017 , Oracle and/or its affiliates. All rights reserved.
2
2
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
@@ -158,6 +158,18 @@ namespace binary_log
158
158
on. </td>
159
159
</tr>
160
160
161
+ <tr>
162
+ <td>optional metadata fields</td>
163
+ <td>optional metadata fields are stored in Type, Length, Value(TLV) format.
164
+ Type takes 1 byte. Length is a packed integer value. Values takes
165
+ Length bytes.
166
+ </td>
167
+ <td>There are some optional metadata defined. They are listed in the table
168
+ @ref Table_table_map_event_optional_metadata. Optional metadata fields
169
+ follow null_bits. Whether binlogging an optional metadata is decided by the
170
+ server. The order is not defined, so they can be binlogged in any order.
171
+ </td>
172
+ </tr>
161
173
</table>
162
174
163
175
The table below lists all column types, along with the numerical
@@ -363,6 +375,88 @@ namespace binary_log
363
375
</tr>
364
376
365
377
</table>
378
+
379
+ The table below lists all optional metadata types, along with the numerical
380
+ identifier for it and the size and interpretation of meta-data used
381
+ to describe the type.
382
+
383
+ @anchor Table_table_map_event_optional_metadata
384
+ <table>
385
+ <caption>Table_map_event optional metadata types: numerical identifier and
386
+ metadata. Optional metadata fields are stored in TLV fields.
387
+ Format of values are described in this table. </caption>
388
+ <tr>
389
+ <th>Type</th>
390
+ <th>Description</th>
391
+ <th>Format</th>
392
+ </tr>
393
+ <tr>
394
+ <td>SIGNEDNESS</td>
395
+ <td>signedness of numeric colums</td>
396
+ <td>For each numeric column, a bit indicates whether the numeric colunm has
397
+ unsigned flag. 1 means it is unsigned. The number of bytes needed for this is
398
+ int((column_count + 7) / 8). The order is same to the order of column_type
399
+ field.</td>
400
+ </tr>
401
+ <tr>
402
+ <td>DEFAULT_CHARSET</td>
403
+ <td>Charsets of character columns. It has a default charset for the case
404
+ that most of character columns have same charset and the most used charset
405
+ is binlogged as default charset.Collation numbers are binlogged for
406
+ identifying charsets. They are stored in packed length format. </td>
407
+ <td>Default charset's collation is logged first. The charsets which are not
408
+ same to default charset are logged following default charset. They are
409
+ logged as column index and charset collation number pair sequence. The
410
+ column index is counted only in all character columns. The order is same to
411
+ the order of column_type
412
+ field. </td>
413
+ </tr>
414
+ <tr>
415
+ <td>COLUMN_CHARSET</td>
416
+ <td>Charsets of character columns. For the case that most of columns have
417
+ different charsets, this field is logged. It is never logged with
418
+ DEFAULT_CHARSET together.</td>
419
+ <td>It is a collation number sequence for all character columns.</td>
420
+ </tr>
421
+ <tr>
422
+ <td>COLUMN_NAME</td>
423
+ <td>Names of columns</td>
424
+ <td>A sequence of column names. For each column name, 1 byte string length
425
+ followed by a string without null terminator. </td>
426
+ </tr>
427
+ <tr>
428
+ <td>SET_STR_VALUE</td>
429
+ <td>The string values of SET columns</td>
430
+ <td>For each SET column, a pack_length presents value count is followed by
431
+ a sequence of length and string pairs. length is pack_length and string
432
+ has no null terminator.</td>
433
+ </tr>
434
+ <tr>
435
+ <td>ENUM_STR_VALUE</td>
436
+ <td>The string values is ENUM columns</td>
437
+ <td>Format is same to SET_STR_VALUE</td>
438
+ </tr>
439
+ <tr>
440
+ <td>GEOMETRY_TYPE</td>
441
+ <td>The real type of geometry columns</td>
442
+ <td>A sequence of real type of geometry columns are stored in pack_length
443
+ format. </td>
444
+ </tr>
445
+ <tr>
446
+ <td>SIMPLE_PRIMARY_KEY</td>
447
+ <td>The primary key without any prefix</td>
448
+ <td>A sequence of column indexes. The indexes are stored in pack_length
449
+ format.</td>
450
+ </tr>
451
+ <tr>
452
+ <td>PRIMARY_KEY_WITH_PREFIX</td>
453
+ <td>The primary key with some prefix. It doesn't appear with
454
+ SIMPLE_PRIMARY_KEY together. </td>
455
+ <td>A sequence of column index and prefix length pairs. Both
456
+ column index and prefix length are in pack_length format. It means
457
+ the whole value is used even if prefix length is 0.</td>
458
+ </tr>
459
+ </table>
366
460
*/
367
461
class Table_map_event: public Binary_log_event
368
462
{
@@ -376,6 +470,77 @@ class Table_map_event: public Binary_log_event
376
470
377
471
typedef uint16_t flag_set;
378
472
473
+ /* *
474
+ DEFAULT_CHARSET and COLUMN_CHARSET don't appear together. They are just two
475
+ ways to pack character set information. When binlogging, it just log
476
+ character set in the way which occupy less storage.
477
+
478
+ SIMPLE_PRIMARY_KEY and PRIMARY_KEY_WITH_PREFIX don't appear together.
479
+ SIMPLE_PRIMARY_KEY is for the primary keys which only use whole values of
480
+ pk columns. PRIMARY_KEY_WITH_PREFIX is
481
+ for the primary keys which just use part value of pk columns.
482
+ */
483
+ enum Optional_metadata_field_type
484
+ {
485
+ SIGNEDNESS= 1 , // UNSIGNED flag of numeric columns
486
+ DEFAULT_CHARSET, // Default character set of string columns
487
+ COLUMN_CHARSET, // Character set of string columns
488
+ COLUMN_NAME,
489
+ SET_STR_VALUE, // String value of SET columns
490
+ ENUM_STR_VALUE, // String value of ENUM columns
491
+ GEOMETRY_TYPE, // Real type of geometry columns
492
+ SIMPLE_PRIMARY_KEY, // Primary key without prefix
493
+ PRIMARY_KEY_WITH_PREFIX // Primary key with prefix
494
+ };
495
+
496
+ /* *
497
+ Metadata_fields organizes m_optional_metadata into a structured format which
498
+ is easy to access.
499
+ */
500
+ struct Optional_metadata_fields
501
+ {
502
+ typedef std::pair<unsigned int , unsigned int > uint_pair;
503
+ typedef std::vector<std::string> str_vector;
504
+
505
+ struct Default_charset
506
+ {
507
+ Default_charset () : default_charset (0 ) {}
508
+ bool empty () const { return default_charset == 0 ; }
509
+
510
+ // Default charset for the columns which are not in charset_pairs.
511
+ unsigned int default_charset;
512
+
513
+ /* The uint_pair means <column index, column charset number>. */
514
+ std::vector<uint_pair> charset_pairs;
515
+ };
516
+
517
+ // Content of DEFAULT_CHARSET field is converted into Default_charset.
518
+ Default_charset m_default_charset;
519
+ std::vector<bool > m_signedness;
520
+ // Character set number of every column
521
+ std::vector<unsigned int > m_column_charset;
522
+ std::vector<std::string> m_column_name;
523
+ // each str_vector stores values of one enum/set column
524
+ std::vector<str_vector> m_enum_str_value;
525
+ std::vector<str_vector> m_set_str_value;
526
+ std::vector<unsigned int > m_geometry_type;
527
+ /*
528
+ The uint_pair means <column index, prefix length>. Prefix length is 0 if
529
+ whole column value is used.
530
+ */
531
+ std::vector<uint_pair> m_primary_key;
532
+
533
+ /*
534
+ It parses m_optional_metadata and populates into above variables.
535
+
536
+ @param[in] optional_metadata points to the begin of optional metadata
537
+ fields in table_map_event.
538
+ @param[in] optional_metadata_len length of optional_metadata field.
539
+ */
540
+ Optional_metadata_fields (unsigned char * optional_metadata,
541
+ unsigned int optional_metadata_len);
542
+ };
543
+
379
544
/* *
380
545
<pre>
381
546
The buffer layout for fixed data part is as follows:
@@ -418,7 +583,9 @@ class Table_map_event: public Binary_log_event
418
583
m_colcnt (colcnt),
419
584
m_field_metadata_size (0 ),
420
585
m_field_metadata (0 ),
421
- m_null_bits (0 )
586
+ m_null_bits (0 ),
587
+ m_optional_metadata_len (0 ),
588
+ m_optional_metadata (NULL )
422
589
{
423
590
if (dbnam)
424
591
m_dbnam= std::string (dbnam, m_dblen);
@@ -449,13 +616,17 @@ class Table_map_event: public Binary_log_event
449
616
unsigned long m_field_metadata_size;
450
617
unsigned char * m_field_metadata; /* * field metadata */
451
618
unsigned char * m_null_bits;
619
+ unsigned int m_optional_metadata_len;
620
+ unsigned char * m_optional_metadata;
452
621
453
622
Table_map_event ()
454
623
: Binary_log_event (TABLE_MAP_EVENT),
455
624
m_coltype (0 ),
456
625
m_field_metadata_size (0 ),
457
626
m_field_metadata (0 ),
458
- m_null_bits (0 )
627
+ m_null_bits (0 ),
628
+ m_optional_metadata_len (0 ),
629
+ m_optional_metadata (NULL )
459
630
{}
460
631
461
632
unsigned long long get_table_id ()
0 commit comments