public function get_nullable_fields_in_index($xmldb_table, $xmldb_index) {
        global $DB;

        // If we don't have the field info passed in, we need to query it from the DB.
        $fieldsfromdb = null;

        $nullablefields = [];
        foreach ($xmldb_index->getFields() as $fieldname) {
            if ($field = $xmldb_table->getField($fieldname)) {
                // We have the field details in the table definition.
                if ($field->getNotNull() !== XMLDB_NOTNULL) {
                    $nullablefields[] = $fieldname;
                }

            } else {
                // We don't have the table definition loaded. Need to
                // inspect the database.
                if ($fieldsfromdb === null) {
                    $fieldsfromdb = $DB->get_columns($xmldb_table->getName(), false);
                }
                if (!isset($fieldsfromdb[$fieldname])) {
                    throw new coding_exception('Unknown field ' . $fieldname .
                            ' in index ' . $xmldb_index->getName());
                }

                if (!$fieldsfromdb[$fieldname]->not_null) {
                    $nullablefields[] = $fieldname;
                }
            }
        }

        return $nullablefields;
    }