Coder Social home page Coder Social logo

project-tsurugi / tsurugi_fdw Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 10.67 MB

PostgreSQL Foreign Data Wrapper for Tsurugi.

License: Apache License 2.0

Makefile 0.37% C 42.31% C++ 55.42% Shell 0.01% PLpgSQL 1.90%
foreign-data-wrapper postgresql-extension postgressql sql tsurugidb

tsurugi_fdw's People

Contributors

akirakw avatar fujita-kin avatar hiro-yano avatar kitajima-y avatar koh-okada avatar noz-yanagisawa avatar t-horikawa avatar t-yamane-ti avatar ynamiki avatar

Stargazers

 avatar

Watchers

 avatar  avatar

tsurugi_fdw's Issues

PL/pgSQLからのクエリ実行に対応させる(#93)

事象
PL/pgSQLからSELECT文が実行される場合、SQL文末に「;」は存在しない。
この時、ogawayamaIterateForeignScanで行っている処理(query.pop_back())の影響で、末尾一文字が欠損する。

再現ケース

  1. 外部表に対して、以下プロシージャを作成
    CREATE OR REPLACE PROCEDURE DELIVERY (
    d_w_id IN INTEGER,
    d_o_carrier_id IN INTEGER,
    tstamp IN TEXT)
    AS $$
    DECLARE
    d_no_o_id INTEGER;
    d_d_id INTEGER;
    d_c_id INTEGER;
    d_ol_total INTEGER;
    loop_counter INTEGER;
    BEGIN
    FOR loop_counter IN 1 .. 10 LOOP
    d_d_id := loop_counter;
    EXECUTE 'SELECT no_o_id FROM NEW_ORDER WHERE no_w_id = ' || d_w_id || ' AND no_d_id = ' || d_d_id || ' ORDER BY no_o_id' INTO d_no_o_id;
    END LOOP;
    END
    $$ LANGUAGE plpgsql;

  2. プロシージャを実行
    call delivery(1, 1, '2019/10');

エラー内容
2019-11-01 16:16:35.124 JST [15278] ERROR: Transaction::execute_query() failed. (7)
2019-11-01 16:16:35.124 JST [15278] CONTEXT: SQL statement "SELECT no_o_id FROM NEW_ORDER WHERE no_w_id = 1 AND no_d_id = 1 ORDER BY no_o_id"
PL/pgSQL function delivery(integer,integer,text) line 12 at EXECUTE
2019-11-01 16:16:35.124 JST [15278] STATEMENT: call delivery(1, 1, '2019/10');
ERROR: Transaction::execute_query() failed. (7)
CONTEXT: SQL statement "SELECT no_o_id FROM NEW_ORDER WHERE no_w_id = 1 AND no_d_id = 1 ORDER BY no_o_id"
PL/pgSQL function delivery(integer,integer,text) line 12 at EXECUTE

stub apiに渡る直前のSQL文
(gdb) p query
$3 = "SELECT no_o_id FROM NEW_ORDER WHERE no_w_id = 1 AND no_d_id = 1 ORDER BY no_o_i"

★末尾のno_o_idのdが欠損している

JOIN文実行後にSELECT文を実行するとSegmentation faujltが発生する

https://nd-viewer.slack.com/archives/C014R79Q60K/p1674443187798909

INNER JOINをしたSELECT文を実行した後、SELECT文を実行するとエラーになります。
一度postgreSQLからログアウトし再度ログインすると正常に取得できますが、
INNER JOINをした後はログアウトしない限りエラーが発生します。
// SELECT文実行(任意のSQL)
postgres=# SELECT * from map;
 map_id | map_name | map_type | epsg |      init_x       |      init_y       | init_z | init_scale | max_scale | min_scale | description 
--------+----------+----------+------+-------------------+-------------------+--------+------------+-----------+-----------+-------------
   1001 | 2d map   |        1 | 3857 | 15454818.86530255 | 4501176.688619994 |        |         13 |        26 |        10 | 
(1 row)

// INNER JOINしたSELECT文実行
postgres=# SELECT * FROM map INNER JOIN map_layers ON map.map_id = map_layers.map_id;
 map_id | map_name | map_type | epsg |      init_x       |      init_y       | init_z | init_scale | max_scale | min_scale | description | map_id | layer_id | layer_order 
--------+----------+----------+------+-------------------+-------------------+--------+------------+-----------+-----------+-------------+--------+----------+-------------
   1001 | 2d map   |        1 | 3857 | 15454818.86530255 | 4501176.688619994 |        |         13 |        26 |        10 |             |   1001 |        3 |           2
   1001 | 2d map   |        1 | 3857 | 15454818.86530255 | 4501176.688619994 |        |         13 |        26 |        10 |             |   1001 |        3 |           2
(2 rows)

// 成功していたSELECT文を再実行
postgres=# SELECT * from map;
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
使用データを以下に記します。
// map
CREATE TABLE map (
    map_id integer NOT NULL PRIMARY KEY,
    map_name character varying(40) NOT NULL,
    map_type integer NOT NULL,
    epsg integer,
    init_x double precision NOT NULL,
    init_y double precision NOT NULL,
    init_z double precision,
    init_scale integer NOT NULL,
    max_scale integer NOT NULL,
    min_scale integer NOT NULL,
    description character varying(256)
) TABLESPACE tsurugi;

CREATE FOREIGN TABLE map (
    map_id integer NOT NULL,
    map_name character varying(40) NOT NULL,
    map_type integer NOT NULL,
    epsg integer,
    init_x double precision NOT NULL,
    init_y double precision NOT NULL,
    init_z double precision,
    init_scale integer NOT NULL,
    max_scale integer NOT NULL,
    min_scale integer NOT NULL,
    description character varying(256)
) SERVER ogawayama;

INSERT INTO map (map_id, map_name, map_type, epsg, init_x, init_y, init_z, init_scale, max_scale, min_scale, description) VALUES (1001,'2d map',1,3857,15454818.8653025497,4501176.68861999363,NULL,13,26,10,NULL);

// map_layers
CREATE TABLE map_layers (
    map_id integer NOT NULL,
    layer_id integer NOT NULL,
    layer_order integer NOT NULL,
    PRIMARY KEY (map_id, layer_id)
) TABLESPACE tsurugi;

CREATE FOREIGN TABLE map_layers (
    map_id integer NOT NULL,
    layer_id integer NOT NULL,
    layer_order integer NOT NULL
) SERVER ogawayama;

INSERT INTO map_layers (map_id, layer_id, layer_order) VALUES (1001,5,1);
INSERT INTO map_layers (map_id, layer_id, layer_order) VALUES (1001,3,2);
ご検討よろしくお願いいたします。

WHERE句付きSELECT文の実行に失敗する

Pasco殿環境で発生。
https://nd-viewer.slack.com/archives/C014R79Q60K/p1674102517308459

PostgreSQLから条件付きSQLを実行しますと以下のようなエラーが発生します。
postgres=# select * from job_status where block_num = '08EE46271';
2023-01-19 13:06:38.324 JST [2670096] ERROR: Transaction::execute_query() failed. (9)
2023-01-19 13:06:38.324 JST [2670096] STATEMENT: select * from job_status where block_num = '08EE46271';
ERROR: Transaction::execute_query() failed. (9)
条件なしであればエラーは発生しません。
また、Tsurugiから直接同じ条件付きSQLを実行した場合もエラーは発生せず成功します。
DDLとDMLを添付しますので、ご確認お願いできますでしょうか。

select * from job_status where block_num = '08EE46271';

文字列型カラムを指定してSELECT文を実行するとSegmentation faultが発生する

https://nd-viewer.slack.com/archives/C014R79Q60K/p1674178021865319

昨日のデータで、以下のSELECTが失敗するようです。
postgres=# select block_num from job_status;
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: 2023-01-20 09:52:54.191 JST [2791097] LOG:  server process (PID 2792124) was terminated by signal 11: Segmentation fault
2023-01-20 09:52:54.191 JST [2791097] DETAIL:  Failed process was running: select block_num from job_status;
2023-01-20 09:52:54.191 JST [2791097] LOG:  terminating any other active server processes
2023-01-20 09:52:54.191 JST [2792120] WARNING:  terminating connection because of crash of another server process
2023-01-20 09:52:54.191 JST [2792120] DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2023-01-20 09:52:54.191 JST [2792120] HINT:  In a moment you should be able to reconnect to the database and repeat your command.
2023-01-20 09:52:54.192 JST [2792130] FATAL:  the database system is in recovery mode
Failed.
!> 2023-01-20 09:52:54.193 JST [2791097] LOG:  all server processes terminated; reinitializing
2023-01-20 09:52:54.213 JST [2792131] LOG:  database system was interrupted; last known up at 2023-01-20 09:51:11 JST
2023-01-20 09:52:54.235 JST [2792131] LOG:  database system was not properly shut down; automatic recovery in progress
2023-01-20 09:52:54.237 JST [2792131] LOG:  redo starts at 0/1750B78
2023-01-20 09:52:54.237 JST [2792131] LOG:  invalid record length at 0/1750BB0: wanted 24, got 0
2023-01-20 09:52:54.237 JST [2792131] LOG:  redo done at 0/1750B78
2023-01-20 09:52:54.243 JST [2791097] LOG:  database system is ready to accept connections
以下のSELECTは成功します。
postgres=# select * from job_status;
ご確認お願いいたします。

CREATE TABLE文で、transaction::commit()時にogawayamaからNO_TRANSACTIONエラーが返却される。

v1のfrontendのテストで使用されたsql文(添付ファイルのtest_create_table.sql)を発行すると、
「ERROR: transaction::commit() failed. (6)」というエラーメッセージが出力される。ogawayamaのNO_TRANSACTIONというエラーコードに相当する。
ただし、CREATE TABLE文以外のDML文などは正常に動作する。

/* DDL */
CREATE TABLE t1(c1 INTEGER NOT NULL PRIMARY KEY) TABLESPACE tsurugi;
ERROR:  transaction::commit() failed. (6)
CREATE FOREIGN TABLE t1(c1 INTEGER NOT NULL) SERVER ogawayama;
CREATE FOREIGN TABLE
CREATE TABLE t2(c1 INTEGER NOT NULL PRIMARY KEY, c2 BIGINT, c3 DOUBLE PRECISION) TABLESPACE tsurugi;
ERROR:  transaction::commit() failed. (6)
CREATE FOREIGN TABLE t2(c1 INTEGER NOT NULL, c2 BIGINT, c3 DOUBLE PRECISION) SERVER ogawayama;
CREATE FOREIGN TABLE
/* DML */
SELECT * FROM t1;
 c1 
----
(0 rows)

test_create_table..zip

PostgreSQLの起動に失敗する

pg_ctl start実行時に以下のようなメッセージが表示されてPostgreSQLの起動に失敗する。

waiting for server to start....==686647==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
 stopped waiting
pg_ctl: could not start server

回避策

export LSAN_OPTIONS=detect_leaks=0                       
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.4

(TPC-C)Hitory表の扱い

ogawayama-cliで生成されるTPC-Cのテーブル群にHistory表が含まれていない。
理由: Primary Keyを付与しないテーブルであるため (ogawayamaはKVSをベースとしているためテーブルにPrimary Keyが必須)

ORDER BYの並べ替え順序がPostgreSQLと異なる

  • PG: 大文字小文字を判別しない
  • TG: 大文字小文字を判別する?
-- ORDER BY #1
--- PG
SELECT
    *
FROM
    pt2
ORDER BY 
    c6;
 c1 | c2 | c3  | c4  |  c5  |     c6     | c7  
----+----+-----+-----+------+------------+-----
  5 | 55 | 555 | 5.5 | 5.55 | five       | XYZ
  4 |    |     |     |      | NULL       | 
  1 | 11 | 111 | 1.1 | 1.11 | one        | ABC
  3 | 33 | 333 | 3.3 | 3.33 | three      | ABC
  2 | 22 | 222 | 2.2 | 2.22 | two        | XYZ
(5 rows)

--- Tsurugi
SELECT
    *
FROM
    t2
ORDER BY 
    c6;
 c1 | c2 | c3  | c4  |  c5  |     c6     | c7  
----+----+-----+-----+------+------------+-----
  4 |  0 |   0 |   0 |    0 | NULL       | 
  5 | 55 | 555 | 5.5 | 5.55 | five       | XYZ
  1 | 11 | 111 | 1.1 | 1.11 | one        | ABC
  3 | 33 | 333 | 3.3 | 3.33 | three      | ABC
  2 | 22 | 222 | 2.2 | 2.22 | two        | XYZ
(5 rows)

metadata-managerを更新した環境でfrontendのテストに失敗する

frontendのthird_partyのmetadata-managerを最新に更新した環境でfrontendのテストを実行すると以下のエラーでテストに失敗する。

create_table.out

CREATE TABLE t1(c1 INTEGER NOT NULL PRIMARY KEY) TABLESPACE tsurugi;
ERROR:  The table is not found when registing constraints. (name: t1)

テストコマンド

make tests

metadata-manager

k-okada@malta:~/frontend/third_party/metadata-manager$ git log
commit e3310d244122e750f56cb4c1982f3953b0481f20 (HEAD, origin/master, origin/HEAD)
Merge: ddeda3a 166059b
Author: OKADA Kohei <[email protected]>
Date:   Tue Jun 6 11:40:57 2023 +0900

    Merge pull request #68 from project-tsurugi/feature/experimental

    Feature/experimental

alt_planner導入後、cratedbに失敗する

alt_plannerを導入後、以下のコマンドが失敗する

$ createdb ogawayama
createdb: query failed: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
createdb: query was: SELECT pg_catalog.set_config('search_path', '', false)

create tableにおいて、float型columnのdataTypeIdが700ではなく701となる

psqlからtsurugiに対して下記のcreate tableを実行すると、

CREATE FOREIGN TABLE table_for_check (
    colpk INTEGER,
    col3  float,
    col4  double precision
) SERVER ogawayama;

CREATE TABLE table_for_check (
    colpk INTEGER NOT NULL PRIMARY KEY,
    col3  float,
    col4  double precision
) TABLESPACE tsurugi;

ogawayamaに渡されるptee(col3のみ抜粋)は下記となる。col3はfloatで表を作成してるのに、ptreeのdataTypeIdは、 FLOAT32 = 700 ではなく、 FLOAT64 = 701となっている。

        {
            "formatVersion": "1",
            "generation": "1",
            "id": "2",
            "name": "col3",
            "tableId": "1",
            "columnNumber": "2",
            "dataTypeId": "701",
            "dataLength": "",
            "varying": "false",
            "isNotNull": "false",
            "isFuncExpr": "false"
        },

Prepared Statement対応

  • PostgreSQLからTsurugiに対してPrepared文の登録、実行を可能とする
  • アプリケーションからJDBCなどを通じて使用することを想定する

frontendのデリバリ方法について調査、検討する

佐藤さん、鬼木さん
frontendおよび各種manager(metadata, message, authentication)について調査、検討をお願いします。

要件

  1. ビルド環境で作成したfrontendおよび各種managerのバイナリのみをユーザに提供し、(別の)本番システムに適用したい

調査項目

  • ビルド環境と本番システムで(PostgreSQLなどの)バージョンを一致させる必要があるか、どの程度であればバージョンがずれていても動作可能か調べる
  • UbuntuにデフォルトでインストールされるPostgreSQLでの動作可否
  • RedHat(RHEL)の環境でfrontedおよび各種managerをビルド、動作可能か知らべる(優先度:低)
  • その他、実現するために必要前提条件などを調査、検討する

成果物

  • 調査報告書
  • セットアップ手順書 ※通常のセットアップと異なる場合

CREATE TABLEを連続で実行すると失敗することがある

最新(7/7時点)のfrontendでCREATE TABLEを連続で実行すると失敗することがある。

ogawayama観点で確認した結果は以下となります。

検証しました。
CREATE TABLEを連続させるとOKで、間にDMLを入れるとNGでした。
そのDMLをBEGIN;とCOMMIT;で囲ってもNG。
そのときのogawayama (bridge = be側)のtraceは、COMMITが来ていないことを示してました。
auto commitの扱いをどうするか(現在は未サポート)は別途議論が必要と思いますが、
PostgreSQLでCOMMITしてもogawayamaにcommitが伝わらないのが、当方から見えている原因です。
もし、feはogawayama stubにcommitを出している(~ ↓をcallしている)のであれば、stub - bridge間の通信に問題ありということになります。
https://github.com/project-tsurugi/ogawayama/blob/71f942e37430f83c7abc203dfa0400604f151211/stub/include/ogawayama/stub/api.h#L227

ogawayama stubは、現在もfrontendからcommitが来ることを期待しているでしょうか。

話が混ざっているように思います。
DDL(CREATE TABLE)に対してはsessionで処理するBEGIN_DDL、CREATE_TABLE、END_DDLでOKです。
一方、トランザクションからexecuteするDMLに関しては、そのトランザクションが終わったらcommitして頂く必要があります。なので、DMLに関しては、「現在もfrontendからcommitが来ることを期待して」います。

(↑)DMLを実行するトランザクションのcommitなしにBEGIN_DDLを行うと、DML用のトランザクションが終わらない状態でDDLを実行するためのトランザクションを開始しようとするので、TRANSACTION_ALREADY_STARTED(12)となるのは必然の結果です。

従来のDMLの処理に対する調査が必要と考えます。

PostgreSQLと実行エンジン間でのデータ型仕様の相違について検討する

PostgreSQLと実行エンジン間で数値型データの仕様が異なっていることについて対策を検討する。

PostgreSQLの型 (ogawayamaの型) PostgreSQLの仕様1 Tsurugiの仕様
※矢野が実際に値をINSERTしてみて分かった結果
integer (INT32) 範囲外の値はINSERT不可 ・最小値-n(n=1,2,3,...)でINSERTした後、SELECTした結果最大値-(n-1)がINSERTされる。
・最小値・最大値はPostgreSQLと同じ
bigint (INT64) 最小値: -9223372036854775808 ・最小値: PostgreSQLの最小値+1
・最大値はPostgreSQLと同じ
real (FLOAT32) 最大値: 3.402823e+38
最小値:1.175494e-38
精度: 6桁精度
最大値: 1e+18?
最小値:1e-18?
精度:?
double precision (FLOAT64) 最大値: 1.797693e+308
最小値:2.225074e-308
精度: 15桁精度
最大値: 1e+18?
最小値: 1e-18?
精度:?

Footnotes

  1. https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-FLOAT

count関数の戻り値データ型

TPC-Cの実行のためにogawayamaにNumeric(Decimal)型を実装する必要がある。
PostgreSQLのcount関数はbigint型(8 byte)で実装されている。

ORDER BYのデフォルトのNULLS FIRST/LASTがPostgreSQLと異なる

  • PG: NULLS LAST
  • TG: NULLS FIRST
-- ORDER BY #3
-- PG
SELECT
    c1, c4, c5, c6, c7
FROM
    pt2
WHERE
    c1 > 2
ORDER BY
    c7;
 c1 | c4  |  c5  |     c6     | c7  
----+-----+------+------------+-----
  3 | 3.3 | 3.33 | three      | ABC
  5 | 5.5 | 5.55 | five       | XYZ
  4 |     |      | NULL       | 
(3 rows)

-- TG
SELECT
    c1, c4, c5, c6, c7
FROM
    t2
WHERE
    c1 > 2
ORDER BY
    c7;
 c1 | c4  |  c5  |     c6     | c7  
----+-----+------+------------+-----
  4 |   0 |    0 | NULL       | 
  3 | 3.3 | 3.33 | three      | ABC
  5 | 5.5 | 5.55 | five       | XYZ
(3 rows)

テーブル名のlowercase/uppercaseの区別について(Minor)

  • PostgreSQLからuppercaseでテーブルを定義する
    • PostgreSQL内ではlowercaseに変換される
    • 統合メタデータ管理基盤上もlowercaseでテーブル名を定義される
  • SELECT時にテーブル名をuppercaseで指定した場合の挙動がPostgreSQLと実行エンジンで異なる
    • PostgreSQL
      • 成功する(lowercase/uppercaseを区別しない)
    • 実行エンジン
      • 失敗する(lowercase/uppercaseを区別する)

LTx対応 & DDL閉塞実行機能

  • TsurugiのLTx(Long Transaction)をPostgreSQLから実行可能とする
  • PostgreSQLのストプロ(PL/pgSQL)からも実行可能とする
  • DDLとDMLのトランザクションをそれぞれ排他的に制御する

開発用ブランチ

数値型列の値がNULL値の場合に0を返す

INSERT INTO 
    t2(c1, c2, c3, c4, c5, c6, c7)
VALUES
    (4, NULL, NULL, NULL, NULL, 'NULL', NULL);
SELECT * FROM t2;
 c1 | c2 | c3  | c4  |  c5  |     c6     |             c7             
----+----+-----+-----+------+------------+----------------------------
  1 | 11 | 111 | 1.1 | 1.11 | one        | ABCDEFGHIJKLMNOPQRSTUVWXYZ
  2 | 22 | 222 | 2.2 | 2.22 | two        | ABCDEFGHIJKLMNOPQRSTUVWXYZ
  3 | 33 | 333 | 3.3 | 3.33 | three      | ABCDEFGHIJKLMNOPQRSTUVWXYZ
  4 |  0 |   0 |   0 |    0 | NULL       | 
(4 rows)

alt_plannerのCIへの組み込み

@akirakw 本リポジトリにあるもうひとつのコンポーネントであるalt_plannerもCIに組み入れていただけますか? 手順は 文書 にあるとおり、 alt_planner ディレクトリに移動して make && make install です。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.