-
Notifications
You must be signed in to change notification settings - Fork 2
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
ast2sqlでviewのΔに対してinsert/deleteを出力しない #49
Conversation
9130a64
to
f1a4435
Compare
f1a4435
to
9a4d524
Compare
src/ast2sql.ml
Outdated
@@ -2505,6 +2505,7 @@ let convert_expr_to_operation_based_sql (expr : expr) : (sql_operation list, err | |||
table_env |> TableEnv.add table cols | |||
) TableEnv.empty | |||
in | |||
let (view_name, _) = get_view expr in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
view_nameを取得
@@ -2559,7 +2560,7 @@ let convert_expr_to_operation_based_sql (expr : expr) : (sql_operation list, err | |||
get_column_names_from_table ~error_detail:(InGroup delta_key) table_env table >>= fun cols -> | |||
let delta_env = delta_env |> DeltaEnv.add delta_key (temporary_table, cols) in | |||
let creation = SqlCreateTemporaryTable (temporary_table, sql_query) in | |||
if TableSet.mem table existent_tables then | |||
if Option.fold ~none:true ~some:((<>) table) view_name && TableSet.mem table existent_tables then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
viewに対するΔ述語だったら除外
@@ -2505,6 +2505,7 @@ let convert_expr_to_operation_based_sql (expr : expr) : (sql_operation list, err | |||
table_env |> TableEnv.add table cols | |||
) TableEnv.empty | |||
in | |||
let view_name = expr.view |> Option.map (fun (view_name, _) -> view_name) in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
option
@hiroshi-cl
|
こちらの1, 2番目の指摘事項なのですが、HEADでも起きていることなのでこのPRによるものではなさそうです。 CREATE TEMPORARY TABLE temp0 AS SELECT a_0.A AS A, a_0.B AS B, 3 AS C FROM a AS a_0, b AS b_1 WHERE b_1.B = a_0.B AND b_1.C = 3 AND a_0.A <> 4;
CREATE TEMPORARY TABLE __updated__v AS SELECT a_0.A AS A, a_0.B AS B, b_1.C AS C FROM a AS a_0, b AS b_1 WHERE b_1.B = a_0.B AND NOT EXISTS ( SELECT * FROM temp0 AS t WHERE t.A = a_0.A AND t.B = a_0.B AND t.C = b_1.C ) UNION SELECT 4 AS A, a_0.B AS B, 3 AS C FROM a AS a_0, b AS b_1 WHERE b_1.B = a_0.B AND b_1.C = 3 AND a_0.A <> 4;
CREATE TEMPORARY TABLE temp1 AS SELECT 4 AS A, a_0.B AS B FROM a AS a_0, b AS b_1 WHERE b_1.B = a_0.B AND b_1.C = 3 AND a_0.A <> 4 AND NOT EXISTS ( SELECT * FROM a AS t WHERE t.A = 4 AND t.B = a_0.B );
CREATE TEMPORARY TABLE temp2 AS SELECT a_0.B AS B, b_1.C AS C FROM a AS a_0, b AS b_1, b AS b_2 WHERE b_1.B = a_0.B AND b_2.B = a_0.B AND NOT EXISTS ( SELECT * FROM temp0 AS t WHERE t.A = a_0.A AND t.B = a_0.B AND t.C = b_2.C ) AND NOT EXISTS ( SELECT * FROM __updated__v AS t WHERE t.B = a_0.B AND t.C = b_1.C ) UNION SELECT a_0.B AS B, b_1.C AS C FROM a AS a_0, b AS b_1, b AS b_2 WHERE b_1.B = a_0.B AND b_2.B = a_0.B AND b_2.C = 3 AND a_0.A <> 4 AND NOT EXISTS ( SELECT * FROM __updated__v AS t WHERE t.B = a_0.B AND t.C = b_1.C );
CREATE TEMPORARY TABLE temp3 AS SELECT a_0.A AS A, a_0.B AS B FROM a AS a_0 WHERE NOT EXISTS ( SELECT * FROM __updated__v AS t WHERE t.A = a_0.A AND t.B = a_0.B );
DELETE FROM v USING temp0 WHERE v.A = temp0.A AND v.B = temp0.B AND v.C = temp0.C;
INSERT INTO a SELECT * FROM temp1;
DELETE FROM b USING temp2 WHERE b.B = temp2.B AND b.C = temp2.C;
DELETE FROM a USING temp3 WHERE a.A = temp3.A AND a.B = temp3.B; |
別PRでのご対応とのこと、よろしくお願いいたします。 |
意図しない差分があったので調査していたのですが、 #47 が未反映だったためでした |
HEADを取り込んだ後の差分 CREATE TEMPORARY TABLE temp1 AS SELECT 4 AS A, a_0.B AS B FROM a AS a_0, b AS b_1 WHERE b_1.B = a_0.B AND b_1.C = 3 AND a_0.A <> 4 AND NOT EXISTS ( SELECT * FROM a AS t WHERE t.A = 4 AND t.B = a_0.B );
CREATE TEMPORARY TABLE temp2 AS SELECT a_0.B AS B, b_1.C AS C FROM a AS a_0, b AS b_1, b AS b_2 WHERE b_1.B = a_0.B AND b_2.B = a_0.B AND NOT EXISTS ( SELECT * FROM temp0 AS t WHERE t.A = a_0.A AND t.B = a_0.B AND t.C = b_2.C ) AND NOT EXISTS ( SELECT * FROM __updated__v AS t WHERE t.B = a_0.B AND t.C = b_1.C ) UNION SELECT a_0.B AS B, b_1.C AS C FROM a AS a_0, b AS b_1, b AS b_2 WHERE b_1.B = a_0.B AND b_2.B = a_0.B AND b_2.C = 3 AND a_0.A <> 4 AND NOT EXISTS ( SELECT * FROM __updated__v AS t WHERE t.B = a_0.B AND t.C = b_1.C );
CREATE TEMPORARY TABLE temp3 AS SELECT a_0.A AS A, a_0.B AS B FROM a AS a_0 WHERE NOT EXISTS ( SELECT * FROM __updated__v AS t WHERE t.A = a_0.A AND t.B = a_0.B );
-DELETE FROM v USING temp0 WHERE v.A = temp0.A AND v.B = temp0.B AND v.C = temp0.C;
INSERT INTO a SELECT * FROM temp1;
DELETE FROM b USING temp2 WHERE b.B = temp2.B AND b.C = temp2.C;
DELETE FROM a USING temp3 WHERE a.A = temp3.A AND a.B = temp3.B; |
Thanks! LGTM |
概要
#46 (2-2)
を実現するパッチです
方針
通常 dl2u コマンド (ast2sql.ml) では、
-a
のようなΔ述語のDatalog式に対して以下のような2行のSQLを出力するここで、ビューに対するΔ述語のときはDELETEを出力したくないが、テンポラリテーブルの方は変わらず参照が必要とのことであった。
そこで、今回の対応では単純にΔ述語がビューに対するものかどうか判定して、ビューに対するもののときはDELETEの出力だけ抑制するようにする。
また
+
およびINSERT
についても同様に出力抑制の対応を行う。没にした方針
例
#46 に示されている例を使う
入力 (dl2u_2-2.dl)
実行コマンド
望ましい出力例
出力
望ましい例では
temp0
->mv
,temp1
->temp0
,temp2
->temp1
とリネームされていたが、改修前と同じテンポラリテーブル名をそのまま使っている