* Marc Alff <marc.alff@stripped> [08/07/23 04:39]:
> +/**
> + Abstract representation of a statement.
> + This class is an interface between the parser and the runtime.
> + The parser builds the appropriate sub classes of SQLCOM_statement
> + to represent a SQL statement in the parsed tree.
> + The execute() method in the sub classes contain the runtime implementation.
> + Note that this interface is used for SQL statement recently implemented,
> + the code for older statements tend to load the LEX structure with more
> + attributes instead.
> + The recommended way to implement new statements is to sub-class
> + SQLCOM_statement, as this improves code modularity (see the 'big switch' in
> + dispatch_command()), and decrease the total size of the LEX structure
> + (therefore saving memory in stored programs).
> +*/
> +class SQLCOM_statement : public Sql_alloc
> +{
> +public:
> + /**
> + Execute this SQL statement.
> + @param thd the current thread.
> + @return 0 on success.
> + */
> + virtual int execute(THD *thd) = 0;
What a nice way to sneak in an architecture change in scope of a
task that has no low level design!
Making sure that the rest of the code follows the new scheme will
be of course someone else's burden...
And of course the interface is incomplete -- if you tried to implement
it for any non-trivial existing statement you would have noticed
right away. It is missing "bool prepare()", to start with,
"bool has_result_set() const", "bool send_result_set_metadata()",
and some others.
If you want to make the change happen, do it at least semi-right -- make
sure the minimal life cycle of a C++ class is preserved (see the
next email) and make the interface prepared-statements friendly.
--