MariaDB determine json from Extended Metadata#1423
Open
grooverdan wants to merge 1 commit intobrianmario:masterfrom
Open
MariaDB determine json from Extended Metadata#1423grooverdan wants to merge 1 commit intobrianmario:masterfrom
grooverdan wants to merge 1 commit intobrianmario:masterfrom
Conversation
dr-m
reviewed
Feb 20, 2026
ext/mysql2/result.c
Outdated
|
|
||
| if (!mariadb_field_attr(&field_attr, field, | ||
| MARIADB_FIELD_ATTR_FORMAT_NAME)) { | ||
| return field_attr.length == 4 && strncmp(field_attr.str, "json", 4) == 0; |
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_typecompiles to 0 the MySQL connector as its usingmariadb_field_attrfrom MariaDB Connector/C.JSON is supported on all MariaDB supported version so I've just dropped the version check.