Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-13916

Enforce check constraint on JSON type

Details

    • Task
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.4.3
    • JSON
    • None

    Description

      Since there's no context where someone will want a JSON type without the constraint, and excluding it causes compatibility problems with MySQL, why not map

      CREATE TABLE t (j JSON);
      

      to

      CREATE TABLE t (
        j JSON 
        CHECK (JSON_VALID(j))
      );
      

      Attachments

        Issue Links

          Activity

            I considered that in MDEV-13313. To quote

            auto-adding a constraint is questionable. An unexpected constraint in the table definition, performance implications, strange errors if one manually specifies some constraint for this column.

            that's why I haven't done it. Basically, I can see some users being for and some being against this feature and I cannot say what approach will work best for them all.

            serg Sergei Golubchik added a comment - I considered that in MDEV-13313 . To quote auto-adding a constraint is questionable. An unexpected constraint in the table definition, performance implications, strange errors if one manually specifies some constraint for this column. that's why I haven't done it. Basically, I can see some users being for and some being against this feature and I cannot say what approach will work best for them all.

            Talked with Sergei and we agree to do this with two small changes:

            • The resulting field type will be TEXT, not JSON as we don't yet have a JSON type
            • MariaDB will add an automatic constraint JSON_VALID(field_name) for all JSON fields that doesn't already have a constraint.
              This is to avoid getting things like 'JSON_VALID(field_name) AND JSON_VALID(field_name)' in the check constraint. This is a small
              restriction and one can easily go around it by using table level constraint for "field_name"
            monty Michael Widenius added a comment - Talked with Sergei and we agree to do this with two small changes: The resulting field type will be TEXT, not JSON as we don't yet have a JSON type MariaDB will add an automatic constraint JSON_VALID(field_name) for all JSON fields that doesn't already have a constraint. This is to avoid getting things like 'JSON_VALID(field_name) AND JSON_VALID(field_name)' in the check constraint. This is a small restriction and one can easily go around it by using table level constraint for "field_name"

            Pushed into 10.4

            monty Michael Widenius added a comment - Pushed into 10.4

            People

              monty Michael Widenius
              greenman Ian Gilfillan
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.