Skip to content

MariaDB determine json from Extended Metadata#1423

Open
grooverdan wants to merge 1 commit intobrianmario:masterfrom
grooverdan:json
Open

MariaDB determine json from Extended Metadata#1423
grooverdan wants to merge 1 commit intobrianmario:masterfrom
grooverdan:json

Conversation

@grooverdan
Copy link
Contributor

In MariaDB the JSON of a result value is from the extended metadata of the protocol.

This is returned when PROTOCOL_41 is in the connection flags.

ref: https://mariadb.com/docs/server/reference/clientserver-protocol/4-server-response-packets/result-set-packets#extended-metadata

rb_mariadb_json_type compiles to 0 the MySQL connector as its using mariadb_field_attr from MariaDB Connector/C.

JSON is supported on all MariaDB supported version so I've just dropped the version check.


if (!mariadb_field_attr(&field_attr, field,
MARIADB_FIELD_ATTR_FORMAT_NAME)) {
return field_attr.length == 4 && strncmp(field_attr.str, "json", 4) == 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we can rely on the short-circuit evaluation of the length, and just compare 4 bytes using memcmp, which the compiler can replace with equivalent instructions. https://godbolt.org/z/K8Wz7sn7P demonstrates that the memcmp variant would be much shorter and avoid a call to a library function.

In MariaDB the JSON of a result value is from
the extended metadata of the protocol.

This is returned when PROTOCOL_41 is in
the connection flags.

Thanks Marko Mäkelä for noting memcmp compiles
to less code.

ref: https://mariadb.com/docs/server/reference/clientserver-protocol/4-server-response-packets/result-set-packets#extended-metadata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants