Skip to content

MDEV-18827 Create utility to parse frm files and print their DDL#4094

Draft
hp77-creator wants to merge 2 commits into
MariaDB:mainfrom
hp77-creator:add_frm_util
Draft

MDEV-18827 Create utility to parse frm files and print their DDL#4094
hp77-creator wants to merge 2 commits into
MariaDB:mainfrom
hp77-creator:add_frm_util

Conversation

@hp77-creator

@hp77-creator hp77-creator commented Jun 8, 2025

Copy link
Copy Markdown

Add FRM parser as a standalone utility to mariaDB server

  • The Jira issue number for this PR is: MDEV-18827

Description

The following tests are going to be added and run with mtr:

  • simple columns, at least int, text, varchar(value)
  • keys, using btree
  • keys using rtree
  • sinple vcol expressions: a int, x int as (a *2)
  • same for DEFAULT: a int default (whatever)
  • DEFAULT CURRENT_TIMESTAMP is a special case
  • field-level comments, table-level comments

==================

  • innodb engine
  • more exotic engines
  • engine options
  • partitions -- currently failing so added with error clause

==================

  • Expressions from plugins, like json, Item_geometry_func, inet6 -- currently failing so added with error clause
  • Sequences: default(nextval(s))

==================

  • Foreign keys in innodb -- foreign key constraints are not printed properly

Release Notes

TODO: What should the release notes say about this change?
Include any changed system variables, status variables or behaviour. Optionally list any https://mariadb.com/kb/ pages that need changing.

How can this PR be tested?

Consult the documentation on "Writing good test cases".

run

> ./mtr --suite=client --do-test=mariadb-frm

If the changes are not amenable to automated testing, please explain why not and carefully describe how to test manually.

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@svoj svoj added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Jun 8, 2025
Comment thread extra/frm_parser.cc Outdated
@CLAassistant

CLAassistant commented Jul 3, 2025

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@FooBarrior FooBarrior changed the title add frm_parser MDEV-18827 Create utility to parse frm files and print their DDL Jul 3, 2025
@vuvova vuvova added the GSoC label Jul 16, 2025
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated

@FooBarrior FooBarrior left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now it looks directed to the right way.

I noticed there are some junk files included into PR -- pls rollback them.
Add a test: create a table with a real server and invoke your frm parser with MTR's --exec

Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated

@FooBarrior FooBarrior left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall looks good, I just commented a few creeps about the style, and I think many declarations might be redundand. (I guess that could be left from our past trials with bringing up the minimal linkage...)

You can test it all as follows:

create table t (x int); # will be executed by server
 --exec $MARIADB_FRM $MYSQL_TEST_DIR/std_data/frm/table_simple.frm
drop table t;

# etc, etc, etc...

to test different storage engine, add in the beginning:

--source include/have_innodb.inc
--source include/have_partition.inc
# and for example
--source include/have_blackhole.inc

What needs to be tested:

  • simple columns, at least int, text, varchar(value)
  • keys, using btree, using rtree
  • sinple vcol expressions: a int, x int as (a *2)
  • same for DEFAULT: a int default (whatever)
  • DEFAULT CURRENT_TIMESTAMP is a special case
  • field-level comments, table-level comments

Later on:

  • innodb engine
  • more exotic engines
  • engine options
  • Partitions!!

Later on:

  • Expressions from plugins, like json, Item_geometry_func, inet6
  • sequences: default(nextval(s))

Later on:

  • Foreign keys in innodb

This is the full roadmap remaining, as I see it. I think we won't reach full support for everythink written in time, but at least:

  • We shouldn't crash on those cases.
  • We need to add an information on what's not supported in the commit message
  • A test showing it's not crasing is still needed.

Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/frm_mocks.cc Outdated
Comment thread extra/mariadbfrm/frm_mocks.cc
Comment thread extra/mariadbfrm/frm_mocks.cc
Comment thread extra/mariadbfrm/frm_mocks.cc
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc Outdated
@hp77-creator hp77-creator force-pushed the add_frm_util branch 2 times, most recently from c87bbcc to 8042a41 Compare August 27, 2025 19:06

@FooBarrior FooBarrior left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for your work @hp77-creator!

I really like a steady collection of tests.

About the code - I see some functions handle unexistent error codes, etc, making me think that it's AI generated. If that's so, it should be reverted.

AI is nothing bad in general, but the author should know what are they doing and validate the output.

For supporting the arbitrary expressions, I suggest you examine the following approach

  1. Inherit an own Item, like Frm_parser_item
  2. This item will do nothing but output an expression string it was supplied with through a constructor, in Frm_parser_item::print()
  3. In unpack_vcol_info_from_frm:
    #ifdef FRM_PARSER
    return new Virtual_column_info(new Frm_parser_item(expr_str->c_ptr_safe(), expr_str->length())));
    #endif
    3.1. To make it work, youll have to add table.cc explicitly in the sources list! So that the macro would take effect.
    3.2 Alternatively, make a global variable denoting an frm parser mode
    3.3 Alternatively again, open_table_from_share->...->unpack_vcol_info_from_frm call chaing with an extra argument, denoting frm parser mode. This is the cleanest solution out of proposed.

Should work!

About the storage engines -- given that we already have a working mockup, an arbitrary engine should just work. The question is only in how to test it.

For expample, EXAMPLE storage engine can be enabled with supplying -DWITH_EXAMPLE_STORAGE_ENGINE=1 in the cmake line.

Then have_example_plugin.inc should work in tests after you'll build the target.

Comment thread extra/mariadbfrm/frm_error_handler.cc Outdated
Comment thread extra/mariadbfrm/frm_error_handler.cc Outdated
Comment thread extra/mariadbfrm/frm_error_handler.cc Outdated
Comment thread extra/mariadbfrm/frm_error_handler.cc Outdated
Comment thread extra/mariadbfrm/frm_error_handler.cc Outdated
Comment thread extra/mariadbfrm/frm_error_handler.cc Outdated
Comment thread extra/mariadbfrm/frm_error_handler.cc Outdated
Comment thread extra/mariadbfrm/frm_error_handler.cc Outdated
Comment thread extra/mariadbfrm/mariadb_frm.cc
Comment thread extra/mariadbfrm/frm_error_handler.cc Outdated
@hp77-creator

Copy link
Copy Markdown
Author

About the code - I see some functions handle unexistent error codes, etc, making me think that it's AI generated. If that's so, it should be reverted.

AI is nothing bad in general, but the author should know what are they doing and validate the output.

100% agree, I didn't validate everything it gave and just pushed it, sorry for that, I will go through the comments and fix whatever's hallucinated.

@hp77-creator hp77-creator force-pushed the add_frm_util branch 5 times, most recently from 05be3d9 to f253ade Compare August 31, 2025 17:15
@FooBarrior FooBarrior marked this pull request as ready for review September 4, 2025 12:50
@FooBarrior FooBarrior changed the base branch from main to bb-12.2-frm-staging September 4, 2025 13:43
Comment thread extra/mariadbfrm/CMakeLists.txt Outdated
@hp77-creator hp77-creator force-pushed the add_frm_util branch 5 times, most recently from e50e13f to c5cbd58 Compare September 7, 2025 11:36
@hp77-creator

Copy link
Copy Markdown
Author

@FooBarrior done.

@hp77-creator

Copy link
Copy Markdown
Author

Hey @FooBarrior any plans for this PR?

@FooBarrior

Copy link
Copy Markdown
Contributor

@hp77-creator yes it's queued for adoption and merge

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems to have fallen through and didn't get merged. I'm terribly sorry for that on behalf of the project.
And I fully intend to get it moving again.
I'd like to ask you one more thing before we proceed with the testing required: Can you please rebase on main? This is a new feature and it needs to go to that branch.

@gkodinov gkodinov self-assigned this Mar 17, 2026
@hp77-creator

Copy link
Copy Markdown
Author

Hi @gkodinov , shall I rebase it from MariaDB/server main and then force push the rebased commit?
Although there's only one commit, I am getting conflicts when I am trying to push the local branch which is rebased with MariaDB/server main

@hp77-creator hp77-creator changed the base branch from bb-12.2-frm-staging to main March 22, 2026 11:59
@hp77-creator

Copy link
Copy Markdown
Author

i also changed the PR's base branch to main since staging one was 920 commits behind the current main, let me know if something else needs to be done

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You did the rebase correctly. Unfortunately, when doing that UI alone won't do it (afaik). You also need to rebase your branch by yourself.

Please ensure that the buildbot tests are passing. Right now there's a compilation error:

/home/buildbot/aarch64-debian-11/build/sql/table.cc: In function ‘bool parse_vcol_defs(THD*, MEM_ROOT*, TABLE*, bool*, vcol_init_mode, bool)’:
/home/buildbot/aarch64-debian-11/build/sql/table.cc:1273:96: error: too many arguments to function ‘Virtual_column_info* unpack_vcol_info_from_frm(THD*, TABLE*, String*, Virtual_column_info**, bool*)’
1273 |                                     &((*field_ptr)->vcol_info), error_reported, frm_parser_mode);

Comment thread extra/mariadbfrm/frm_mocks.cc Outdated
@gkodinov

Copy link
Copy Markdown
Member

Do you intend to keep working on this? It's been 3 weeks since I've supplied review comments. Changing to draft due to inactivity. Please change it back when/if you are ready with the next batch.

@gkodinov gkodinov marked this pull request as draft April 27, 2026 10:51
@gkodinov gkodinov added the need feedback Can the contributor please address the questions asked. label Apr 27, 2026
@hp77-creator hp77-creator force-pushed the add_frm_util branch 5 times, most recently from 78ab529 to a105032 Compare May 4, 2026 18:54
@hp77-creator

Copy link
Copy Markdown
Author

Do you intend to keep working on this? It's been 3 weeks since I've supplied review comments. Changing to draft due to inactivity. Please change it back when/if you are ready with the next batch.

yes, I inted to get this merged. sorry for delay. I was occupied in some work stuff. will be more active here

@hp77-creator hp77-creator marked this pull request as ready for review May 4, 2026 18:56
@FooBarrior

FooBarrior commented May 4, 2026

Copy link
Copy Markdown
Contributor

@hp77-creator there is a (unintended) concatenation of various commit messages in your commit message, please check

@hp77-creator

Copy link
Copy Markdown
Author

@hp77-creator there is a (unintended) concatenation of various commit messages in your commit message, please check

snap! I did multiple git rebase, probably that appended messages of every instant, i will amend it, thanks @FooBarrior

- Parse FRM files
- Parse FRM files created in Engines like ARCHIVE, MEMORY, MyISAM, INNODB, CSV, ARIA
- Parse FRM files with default expressions like default(val)
- Parse FRM files that contain mathematical expressions like 1 * 2 * 3
- Parse FRM files containing sequences (exception are frm files of DDL expressions like CREATE SEQUENCE ...)
- Parse FRM files for some plugin functions like JSON (exception: INET and complex geometric functions are not yet supported)
- Provides a --debug option to stack trace in case of failures

Tests for following features are added:
- simple columns, at least int, text, varchar(value)
- keys, using btree
- keys using rtree
- sinple vcol expressions: a int, x int as (a *2)
- same for DEFAULT: a int default (whatever)
- DEFAULT CURRENT_TIMESTAMP is a special case
- field-level comments, table-level comments
- innodb engine
- more exotic engines
- engine options
- partitions -- currently failing so added with error clause
- Expressions from plugins, like json, Item_geometry_func, inet6 -- currently failing so added with error clause
- Sequences: default(nextval(s))
- Foreign keys in innodb

- Applied aggressive linker flags to reduce executable size:
 - Used -Wl, --gc-sections to remove unused sections
 - Applied, -Wl,--strip-all to remove debugging symbols
 - Used -fno-common to remove duplicate symbol error

Reusing existing functions from table.cc to implement this FRM Parser util
@hp77-creator hp77-creator marked this pull request as draft May 4, 2026 20:14
@hp77-creator

Copy link
Copy Markdown
Author

some tests are failing, converting to draft to resolve those. will make it RFR once done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. GSoC need feedback Can the contributor please address the questions asked.

Development

Successfully merging this pull request may close these issues.

7 participants