Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mroonga_command() 等の関数が初期状態で利用できない #75

Open
gaeeyo opened this issue Jul 14, 2022 · 3 comments
Open

mroonga_command() 等の関数が初期状態で利用できない #75

gaeeyo opened this issue Jul 14, 2022 · 3 comments

Comments

@gaeeyo
Copy link

gaeeyo commented Jul 14, 2022

DBのボリュームを削除して初期化した状態で起動します。

docker volume rm hoge

docker run -e MYSQL_ALLOW_EMPTY_PASSWORD=1 --rm -v hoge:/var/lib/mysql:nocopy groonga/mroonga:mysql-8.0-latest

起動した mysql に接続して mroonga_command() を呼び出そうとすると No database selected というエラーになりました。

mysql> SELECT mroonga_command('status');
ERROR 1046 (3D000): No database selected

/usr/share/mroonga/update.sql に CREATE FUNCTION で mroonga_command() 関数を登録する処理が書かれてることがわかったので、実行してみると mroonga_command() 関数が使えるようになりましたが、これは意図的な動作でしょうか?

mysql> \. /usr/share/mroonga/update.sql
Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

mysql> SELECT mroonga_command('status');
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mroonga_command('status')





                                     |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 0x7B22616C6C6F635F636F756E74223A3732332C22737461727474696D65223A313635373736333036302C2273746172745F74696D65223A313635373736333036302C22757074696D65223A3134312C2276657273696F6E223A2231322E302E34222C226E5F71756572696573223A302C2263616368655F6869745F72617465223A302E302C22636F6D6D616E645F76657273696F6E223A312C2264656661756C745F636F6D6D616E645F76657273696F6E223A312C226D61785F636F6D6D616E645F76657273696F6E223A332C226E5F6A6F6273223A302C226665617475726573223A7B226E666B63223A747275652C226D65636162223A747275652C226D6573736167655F7061636B223A747275652C226D72756279223A747275652C226F6E69676D6F223A747275652C227A6C6962223A747275652C226C7A34223A747275652C227A7374616E64617264223A747275652C226B7175657565223A66616C73652C2265706F6C6C223A747275652C22706F6C6C223A66616C73652C2272617069646A736F6E223A747275652C226170616368655F6172726F77223A747275652C22787868617368223A66616C73657D2C226170616368655F6172726F77223A7B2276657273696F6E5F6D616A6F72223A382C2276657273696F6E5F6D696E6F72223A302C2276657273696F6E5F7061746368223A302C2276657273696F6E223A22382E302E30227D2C226D656D6F72795F6D61705F73697A65223A3131373737323238387D |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

レスポンスが16進数になっているのは不思議ですが、デコードすると読むことはできました。

@komainu8
Copy link
Member

komainu8 commented Jul 14, 2022

インストール時に実行されるMroongaのインストールスクリプトの構成を変更したのが原因でMroongaのUDFが自動で登録されない状態になっています。
#74 (comment) のコメントにもあるとおり、mroonga/mroonga#509 と同一問題と思いますが、すみません、まだこの問題を解決しきれていません。
この問題を修正すれば、手動でMroongaのUDFを登録しなくてもよくなりますので、修正版のリリースまでお待ちいただけると幸いです。

レスポンスが16進数になっているのは、別途調べてみます。

@yoku0825
Copy link
Contributor

yoku0825 commented Jul 14, 2022

レスポンスが16進数になっているのはmysqlコマンドラインクライアントの --binary-as-hex=ON がデフォルトになっているせいだと思います(mroonga_commandが MYSQL_TYPE_VAR_STRING あたりで返しているんじゃないかと予想)

https://github.com/mysql/mysql-server/blob/mysql-8.0.29/client/mysql.cc#L3531-L3544

ワークアラウンドとしては、 mysql --binary-as-hex=OFF するとデコードされずに表示されると思います。

@kou
Copy link
Member

kou commented Jul 14, 2022

レスポンスが16進数になっているのはMySQL 8.0からUDFが返す文字列のエンコーディングがデフォルトでbinaryになったからなんですよ。
https://github.com/mysql/mysql-server/blob/mysql-8.0.29/sql/item_func.cc#L4372

MySQL 8.0からは戻り値のメタデータを設定するためのAPIが増えているのでそれでエンコーディングとしてutf8mb4を設定しないといけないんです。
https://github.com/mysql/mysql-server/blob/mysql-8.0.29/include/mysql/components/services/udf_metadata.h#L140-L173

別の回避策はselect convert(mroonga_command('status') using utf8mb4);です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants