I want to analyze a table before a select in mybatis. I can do that via
- create a procedure that does the analyze
- Before the select, run the procude via a select with statementtype=callable via mybatis
So I need a new procedure and a new line in the calling code and a new fragment in the mapper.
Is there a better way?
- Can I somehow add the analyze to the select while keeping it a plain select (not have the two in a function for example)?
- Or can I at least trigger the analyze directly from mybatis without needing the wrapping procedure?
**** UPDATE - How it works via a procedure: ****
<update id="analyzeTable" statementType="CALLABLE">
CALL myschema.analyze_table('myschema.mytable')
</update>
CREATE OR REPLACE PROCEDURE myschema.analyze_table(table_to_analyze regclass)
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path TO ''
AS
$BODY$
DECLARE
v_sql text := format('analyze %s', table_to_analyze);
BEGIN
execute v_sql;
END;
$BODY$;