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

Driver (?mariadb server) returns wrong column nullability in ResultSet

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.5, 11.7(EOL)
    • 10.5
    • None
    • None

    Description

      Table schema

      create table table1(idi1 int not null, idf1 int not null);
      create table table2(idi2 int not null, idf2 int not null);
      create table table3(idi3 int not null, idf3 int not null);
      insert into table1 values(1,2);
      insert into table1 values(2,3);
      insert into table1 values(3,4);
      

      Problem description

      Knowledge of ResultSet column nullability is crucial for convenient developer experience (application stability too).
      I looked at the driver code associated with nullability, and it seems like driver reach nullability throw network protocol.
      I found simple case, where driver fails with nullability:

      var pStmt = connection.prepareStatement("""
          select idi1, idi2, idi3
          from table1 t1
              left join table2 t2 on t1.idf1 = t2.idi2
              inner join table3 t3 on t2.idf2 = t3.idi3
          """);
       
      var metaData = pStmt.getMetaData();
      Assertions.assertEquals(0, metaData.isNullable(1)); // return 0
      Assertions.assertEquals(0, metaData.isNullable(2)); // return 1
      Assertions.assertEquals(0, metaData.isNullable(3)); // return 0
      

      So, Oracle give correct answer.

      Attachments

        Activity

          After modifying mysqltest.cc as

          --- a/client/mysqltest.cc
          +++ b/client/mysqltest.cc
          @@ -9039,6 +9039,14 @@ void run_prepare_stmt(struct st_connection *cn, struct st_command *command,
               goto end;
             }
           
          +  if (display_metadata)
          +  {
          +    MYSQL_FIELD * STDCALL mariadb_stmt_fetch_fields(MYSQL_STMT *stmt);
          +    MYSQL_FIELD *fields= mariadb_stmt_fetch_fields(stmt);
          +    uint num_fields= mysql_stmt_field_count(stmt);
          +    append_metadata(ds, fields, num_fields);
          +  }
          +
             /*
               Get the warnings from mysql_stmt_prepare and keep them in a
               separate string
          

          The following test

          create table t1(idi1 int not null, idf1 int not null);
          create table t2(idi2 int not null, idf2 int not null);
          create table t3(idi3 int not null, idf3 int not null);
          insert into t1 values(1,2);
          insert into t1 values(2,3);
          insert into t1 values(3,4);
          enable_metadata;
          PS_prepare select idi1, idi2, idi3 from t1 left join t2 on t1.idf1 = t2.idi2 inner join t3 on t2.idf2 = t3.idi3;
          drop table t1, t2, t3;
          

          prints N-Y-N for the "is_null" column in the metadata. If I remove "PS_prepare" part, it prints the correct N-N-N

          serg Sergei Golubchik added a comment - After modifying mysqltest.cc as --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -9039,6 +9039,14 @@ void run_prepare_stmt(struct st_connection *cn, struct st_command *command, goto end; } + if (display_metadata) + { + MYSQL_FIELD * STDCALL mariadb_stmt_fetch_fields(MYSQL_STMT *stmt); + MYSQL_FIELD *fields= mariadb_stmt_fetch_fields(stmt); + uint num_fields= mysql_stmt_field_count(stmt); + append_metadata(ds, fields, num_fields); + } + /* Get the warnings from mysql_stmt_prepare and keep them in a separate string The following test create table t1(idi1 int not null , idf1 int not null ); create table t2(idi2 int not null , idf2 int not null ); create table t3(idi3 int not null , idf3 int not null ); insert into t1 values (1,2); insert into t1 values (2,3); insert into t1 values (3,4); enable_metadata; PS_prepare select idi1, idi2, idi3 from t1 left join t2 on t1.idf1 = t2.idi2 inner join t3 on t2.idf2 = t3.idi3; drop table t1, t2, t3; prints N-Y-N for the "is_null" column in the metadata. If I remove "PS_prepare" part, it prints the correct N-N-N

          People

            shulga Dmitry Shulga
            dgorodetskiy Gorodetskiy Dmitry
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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