Brian Aker wrote:
> Hi!
>
> My roadblock in getting I_S, FRM, etc done is coming up with a new
> serialized form of a table definition. I've found that I really like
> what Google has done with Protobuffers.
>
> This is the definition I have thus far:
> http://drizzle.wikia.com/wiki/Table_Proto_Definition#Current_Definition
Good work so far. Here are a few comments:
1) Consistency is a Good Thing :)
For some bool attributes, there is a is_ prefix (like is_unsigned). For
others, like primary and key and auto_increment, there is no prefix.
Let's stick to one or the other. Personally, I prefer the is_ prefix as
it makes the resulting code more explicit and readable.
2) Consider an alternate format for the Field definition
Currently, we have:
message Field {
required string name = 1;
required FieldType type = 2;
optional string collation = 3;
optional string comment = 4;
optional bool unique = 5;
optional bool autoincrement = 6;
optional bool key = 7;
optional bool primary = 8;
optional bool is_unsigned = 9;
optional string custom_name = 10;
optional bool is_notnull = 11 [default = false];
optional int32 scale = 12;
optional string characterset = 13;
optional int32 length = 14;
optional string default_value = 15;
repeated string values = 16;
optional bool on_update = 17;
}
I propose making the definition a little more modular, like so:
message FieldOptions {
optional bool is_primary_key = 0 [default = false];
optional bool is_autoincrement = 1 [default = false];
optional bool is_key = 2 [default = false];
optional bool is_variable_width = 3;
optional string default_value = 4;
optional bool on_update = 16; /* Reserve 0 - 15 for most common */
}
message FieldConstraints {
optional bool is_unique = 0 [default = false];
optional bool is_unsigned = 1 [default = false];
optional bool is_nullable = 2 [default = false];
optional string expression = 16; /* Reserve 0 - 15 for most common */
}
message NumericOptions {
optional int32 scale = 0;
optional int32 precision = 1;
}
message StringOptions {
optional int32 length = 0;
optional string character_set = 1; /* Perhaps this can go away */
optional string collation = 2;
}
message Field {
required string name = 0;
required FieldType type = 1;
required FieldOptions = 2;
required FieldConstraints = 3;
optional NumericOptions numeric_options = 4;
optional StringOptions string_options = 5;
optional string custom_name = 6;
repeated string values = 7;
optional string comment = 16; /* Reserve 0 - 15 for most common */
}
Couple things about the above:
* Uses 0 - 15 for most common elements. Proto Buffers has an
optimization that makes the first 16 elements in a message faster to
retrieve, so they recommend putting the most common elements first.
* Breaks many of the things into smaller components which can be
expanded separately. This means that once the compiler is run on the
.proto file, in C++, we'd use something like this:
io:CodedInputStream *istream= get_some_metadata_stream();
drizzle::Field my_field;
if (my_field.ParseFromCodedStream(istream)) {
if (my_field.FieldType() == Field::STRING) {
cout << my_field.string_options.collation;
}
}
You get the picture...
3) I'm uncertain about a few of the attributes.
What is Field.values? Is this for the ENUM and SET (now gone?) data
types? If so, can we push this out to an EnumOptions nested message, as
it is a bit confusing being in the main Field definition.
What is Field.custom_name?
> Foreign Keys have not been defined yet, and the index definition is
> weak. I've put it up on Wikia so that others can take a look at it/offer
> up edits. Right now I have defined out all of the types, but it would be
> possible to shrink these (aka put a bit in for signed/unsigned... use
> collation to define binary or not).
>
> Thoughts? Suggestions? Additions from engine folks?
I've added an alternate version to the Wiki. It's a start...
Cheers,
Jay
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp