8000 feat(mysql): pin joins, derived tables, with queries and views by keys by colinhacks · Pull Request #108 · colinhacks/reylo · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions engine/mysql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod host;
pub mod mysql;
pub mod mysql_collation;
pub mod mysql_derived;
pub mod mysql_keys;
pub mod mysql_nulls;
pub mod mysql_params;
pub mod mysql_shape;
Expand Down
367 changes: 189 additions & 178 deletions engine/mysql/src/mysql.rs

Large diffs are not rendered by default.

756 changes: 756 additions & 0 deletions engine/mysql/src/mysql_keys.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion oracle/cases/mysql_derived_columns/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ union.sql: many () -> { id: int4|int8 }
union_counts.sql: many () -> { n: int8? }
where_rejects_null.sql: many () -> { id: int4, next: int8 }
wildcard.sql: many () -> { id: int4, name: text, email: text?, n: int8 }
with_in_derived.sql: many () -> { n: int8 }
with_in_derived.sql: maybeOne () -> { n: int8 }
with_left_join.sql: many () -> { id: int4, next: int8? }
with_query.sql: many () -> { id: int4, n: int8 }
2 changes: 1 addition & 1 deletion oracle/cases/mysql_errors/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ insert_audited.sql: none (id: int4) -> { }
insert_post.sql: none (id: int4, user_id: int4, title: text) -> { }
insert_user.sql: none (id: int4, email: text, age: int4?) -> { }
select_taxed.sql: many () -> { id: int4|int8, taxed: int4|int8? }
select_view.sql: many (id: int4) -> { id: int4|int8, email: text }
select_view.sql: maybeOne (id: int4) -> { id: int4|int8, email: text }
upsert_user.sql: none (id: int4, email: text, age: int4?) -> { }
2 changes: 1 addition & 1 deletion oracle/cases/mysql_grouped_aggregates/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ having.sql: many () -> { user_id: int4, top: text }
json.sql: many () -> { user_id: int4, by_title: json, notes: [text?] }
left_joined.sql: many () -> { id: int4, top: text? }
left_joined_reduced.sql: many () -> { id: int4, top: text }
param.sql: many (1: int4) -> { user_id: int4, top: int4|int8 }
param.sql: maybeOne (1: int4) -> { user_id: int4, top: int4|int8 }
rollup.sql: many () -> { user_id: int4|int8?, total: numeric?, top: text? }
scalar_subquery.sql: many () -> { id: int4, top: int4|int8? }
select_distinct.sql: many () -> { user_id: int4, top: int4|int8 }
Expand Down
2 changes: 1 addition & 1 deletion oracle/cases/mysql_key_equality/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int_string_literal.sql: many () -> { id: int4 }
int_table_name.sql: maybeOne (id: int4) -> { id: int4 }
int_true.sql: maybeOne () -> { id: int4 }
int_twice.sql: maybeOne (a: int4, b: int4) -> { id: int4 }
int_view.sql: many (id: int4) -> { id: int4|int8 }
int_view.sql: maybeOne (id: int4) -> { id: int4|int8 }
int_xor.sql: many (id: int4) -> { id: int4 }
prefix_key.sql: maybeOne (name: text) -> { name: text }
prefix_key_scan.sql: maybeOne (name: text) -> { name: text }
Expand Down
4 changes: 2 additions & 2 deletions oracle/cases/mysql_limits/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ count_limit_param.sql: maybeOne (n: int4) -> { n: int8 }
count_offset_0.sql: maybeOne () -> { n: int8 }
count_offset_1.sql: maybeOne () -> { n: int8 }
count_offset_param.sql: maybeOne (skip: int4) -> { n: int8 }
derived_limit.sql: many (id: int4) -> { name: text? }
derived_limit.sql: maybeOne (id: int4) -> { name: text? }
key_comma.sql: maybeOne (id: int8) -> { id: int8, name: text? }
key_limit_0.sql: maybeOne (id: int8) -> { id: int8, name: text? }
key_limit_5.sql: maybeOne (id: int8) -> { id: int8, name: text? }
Expand All @@ -25,4 +25,4 @@ subquery_limit.sql: one () -> { first: text?, n: int8 }
union_limit_1.sql: maybeOne () -> { id: int8 }
union_limit_5.sql: many (id: int4, other: int4) -> { id: int8 }
values_limit.sql: one () -> { column_0: int8|int4, column_1: text }
with_limit.sql: many () -> { n: int8 }
with_limit.sql: maybeOne () -> { n: int8 }
2 changes: 1 addition & 1 deletion oracle/cases/mysql_param_keys/expected.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
case_chooses.sql: many (sort: text) -> { id: int4, name: text }
case_direction.sql: many (desc: text) -> { id: int4, name: text }
group_alone.sql: many (g: text) -> { n: int8 } !! reylo17: group by :g puts every row in one group, since a parameter is a value and not a column's name; choose the column with case :g when 'name' then name end
group_alone.sql: maybeOne (g: text) -> { n: int8 } !! reylo17: group by :g puts every row in one group, since a parameter is a value and not a column's name; choose the column with case :g when 'name' then name end
group_beside.sql: many (g: text) -> { name: text, n: int8 } !! reylo17: group by :g groups every row by the same value, since a parameter is a value and not a column's name; choose the column with case :g when 'name' then name end
in_set_operation.sql: many (s: text) -> { id: int4|int8 } !! reylo17: order by :s sorts every row by the same value, since a parameter is a value and not a column's name; choose the column with case :s when 'name' then name end
in_subquery.sql: many (s: text) -> { id: int4 } !! reylo17: order by :s sorts every row by the same value, since a parameter is a value and not a column's name; choose the column with case :s when 'name' then name end
Expand Down
16 changes: 8 additions & 8 deletions oracle/cases/mysql_row_counts/expected.txt
10BC8
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ aggregate_bit.sql: one () -> { a: int8, o: int8, x: int8 }
aggregate_distinct.sql: one () -> { n: int8 }
aggregate_for_update.sql: one () -> { n: int8 }
aggregate_group_by.sql: many () -> { name: text, n: int8 }
aggregate_group_by_constant.sql: many () -> { n: int8 }
aggregate_group_by_constant.sql: maybeOne () -> { n: int8 }
aggregate_group_concat.sql: one () -> { names: text? }
aggregate_having.sql: many () -> { n: int8 }
aggregate_having_true.sql: many () -> { n: int8 }
Expand All @@ -31,35 +31,35 @@ key_bare_in_join_group.sql: maybeOne (email: text) -> { email: text, n: int8 }
key_composite.sql: maybeOne (post: int4, tag: text) -> { tag: text }
key_composite_partial.sql: many (post: int4) -> { tag: text }
key_cross_join.sql: many (id: int4) -> { id: int4 }
key_derived.sql: many (id: int4) -> { id: int4 }
key_derived.sql: maybeOne (id: int4) -> { id: int4 }
key_exists.sql: maybeOne (id: int4) -> { id: int4 }
key_group_by.sql: maybeOne (id: int4) -> { id: int4, n: int8 }
key_group_by_bare.sql: maybeOne (id: int4) -> { id: int4, n: int8 }
key_group_by_expression.sql: many (id: int4) -> { n: int8 }
key_group_by_expression.sql: maybeOne (id: int4) -> { n: int8 }
key_group_by_having.sql: maybeOne (id: int4) -> { id: int4, n: int8 }
key_group_by_joined_column.sql: many (id: int4) -> { title: text, n: int8 }
key_group_by_other_column.sql: maybeOne (id: int4) -> { name: text, n: int8 }
key_group_by_position.sql: many (id: int4) -> { name: text, n: int8 }
key_group_by_position.sql: maybeOne (id: int4) -> { name: text, n: int8 }
key_group_by_rollup.sql: many (id: int4) -> { id: int4|int8?, n: int8 }
key_group_by_rollup_single.sql: many (id: int4) -> { id: int4|int8?, n: int8 }
key_in_subquery.sql: maybeOne (id: int4) -> { id: int4 }
key_into_variable.sql: none (id: int4) -> { }
key_join.sql: many (id: int4) -> { id: int4, title: text }
key_join_both.sql: many (id: int4, post: int4) -> { id: int4, title: text }
key_join_both.sql: maybeOne (id: int4, post: int4) -> { id: int4, title: text }
key_left_join.sql: many (id: int4) -> { id: int4, title: text? }
key_order_limit.sql: maybeOne (id: int4) -> { id: int4 }
key_parenthesized.sql: many (id: int4) -> { id: int4 }
key_parenthesized_limit.sql: maybeOne () -> { id: int4 }
key_partition.sql: maybeOne (id: int4) -> { id: int4 }
key_straight_join.sql: maybeOne (id: int4) -> { id: int4 }
key_union.sql: many (id: int4, other: int4) -> { id: int4|int8 }
key_view.sql: many (id: int4) -> { id: int4|int8 }
key_view.sql: maybeOne (id: int4) -> { id: int4|int8 }
key_window.sql: maybeOne (id: int4) -> { id: int4, r: int8 }
key_with.sql: many (id: int4) -> { id: int4 }
key_with.sql: maybeOne (id: int4) -> { id: int4 }
key_with_shadows_in_subquery.sql: one () -> { n: int8 }
key_with_shadows_recursive.sql: many (id: int4) -> { id: int8|int4 }
key_with_shadows_table.sql: many (id: int4) -> { id: int8|int4 }
lateral.sql: many (id: int4) -> { id: int4, n: int8 }
lateral.sql: maybeOne (id: int4) -> { id: int4, n: int8 }
no_from.sql: one () -> { one: int8|int4 }
no_from_dual.sql: many () -> { one: int8|int4 }
no_from_dual_where.sql: many () -> { one: int8|int4 }
Expand Down
2 changes: 1 addition & 1 deletion oracle/cases/mysql_server_flags/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ conditionals.sql: many () -> { a: text, b: text, c: int8, d: text?, e: text?, f:
cross_join.sql: many () -> { id: int4, label: text }
date_functions.sql: many () -> { a: date?, b: time?, c: int2?, d: int8|int4?, e: int8|int4?, f: int8|int4?, g: int8|int4?, h: int8|int4?, i: int8|int4?, j: int8|int4?, k: int8|int4?, l: int8|int4?, m: int8|int4?, o: text?, p: text?, q: date?, r: int8|int4?, s: date, u: int8, v: int8, w: timestamp?, x: date?, z: timestamp?, aa: timestamp?, ab: int8|int4?, ac: time?, ad: int8?, ae: text?, af: text?, ag: date?, ah: date?, ai: time?, aj: time?, ak: int8?, al: time?, am: timestamp?, an: int8|int4?, ao: int8?, ap: int8|int4?, aq: int8?, at2: timestamp?, au: timestamp?, av: timestamp?, aw: date?, ax: int8|int4, ay: int8|int4?, az: int8, ba: int8, bb: int8|int4, bc: int8, bd: bool, be: bool }
decimal_and_float.sql: many () -> { a: numeric, b: numeric, c: numeric, d: numeric, e: int8, f: int8, g: numeric, h: float8, i: float8, j: float8, k: float8, l: numeric, m: numeric, o: float8, p: numeric, q: int8, r: text? }
derived_aggregate.sql: many () -> { total: numeric?, top: int4|int8? }
derived_aggregate.sql: maybeOne () -> { total: numeric?, top: int4|int8? }
derived_table.sql: many () -> { name: text, maybe_name: text?, up: text?, c: text }
distinct_and_order.sql: many () -> { name: text, n: int4 }
division.sql: many () -> { a: numeric?, b: numeric?, c: int8?, d: int8?, e: int8?, f: int8?, g: int8?, h: numeric?, i: float8?, j: numeric?, k: numeric?, l: float8?, m: float8?, o: float8?, p: float8?, q: float8?, r: float8? }
Expand Down
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/bare_name.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select id, title from posts) s where id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/comma_join_on_key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select p.title, u.name from posts p, users u where u.id = p.author_id and p.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/compared_as_number.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select email from users) s where s.email = 1
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/cross_join.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select p.id from posts p cross join users u) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/dialect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mysql
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/distinct.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select distinct author_id from posts) s where s.author_id = :a
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/distinct_expression.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select distinct author_id, concat(title, '!') as t from posts) s where s.author_id = :a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select id from scores where rate = 1.5
60 changes: 60 additions & 0 deletions oracle/cases/mysql_subquery_keys/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
bare_name.sql: maybeOne (id: int4) -> { id: int8, title: text }
comma_join_on_key.sql: maybeOne (id: int8) -> { title: text, name: text }
compared_as_number.sql: many () -> { email: text }
cross_join.sql: many (id: int4) -> { id: int8 }
distinct.sql: maybeOne (a: int4) -> { author_id: int8 }
distinct_expression.sql: many (a: int4) -> { author_id: int8, t: text? }
double_key_exact_literal.sql: maybeOne () -> { id: int8 }
expression.sql: many (id: int4) -> { id: int8, title: text }
filtered_inside.sql: maybeOne (a: int4, id: int4) -> { id: int8, title: text }
group_by.sql: maybeOne (a: int4) -> { author_id: int8, n: int8 }
group_by_ordinal.sql: maybeOne (a: int4) -> { author_id: int8, n: int8 }
group_key_hidden.sql: many (n: int4) -> { author_id: int8, n: int8 }
join_double_column.sql: many (id: int8) -> { name: text }
join_many.sql: many (id: int4) -> { id: int8, tag: text }
join_on_key.sql: maybeOne (id: int8) -> { title: text, name: text }
join_pinned.sql: maybeOne (id: int4) -> { id: int8, title: text, name: text }
join_text_column.sql: many (id: int8) -> { title: text, name: text }
join_unpinned.sql: many (id: int8) -> { title: text, name: text }
joined_on_key.sql: maybeOne (id: int8) -> { title: text, name: text }
key_double_arithmetic.sql: many (x: float8) -> { id: int8 }
key_double_cast.sql: many (x: float8) -> { id: int8 }
key_double_constant_cast.sql: maybeOne () -> { id: int8 }
key_double_function.sql: many (x: float8) -> { id: int8 }
key_double_literal.sql: maybeOne () -> { id: int8 }
key_dropped.sql: many (t: text) -> { title: text }
key_exact_function.sql: maybeOne (x: int4) -> { id: int8 }
key_inside.sql: maybeOne (id: int4) -> { id: int8, title: text }
lateral_pinned.sql: maybeOne (u: int8, p: int4) -> { name: text, title: text }
lateral_source.sql: many (id: int4) -> { id: int8 }
left_join_many.sql: many (id: int4) -> { id: int8 }
left_join_on_key.sql: maybeOne (id: int8) -> { title: text, name: text? }
left_join_pinned.sql: maybeOne (id: int4) -> { id: int8, title: text, name: text? }
limit_inside.sql: maybeOne (id: int4) -> { id: int8, title: text }
nested.sql: maybeOne (id: int4) -> { id: int8, title: text }
not_a_key.sql: many (e: text) -> { id: int8, email: text }
null_extended_side.sql: many (id: int4) -> { id: int8?, name: text }
recursive.sql: many (id: int4) -> { id: int8 }
renamed.sql: maybeOne (id: int4) -> { post_id: int8, title: text }
right_join_on_key.sql: maybeOne (id: int8) -> { title: text, name: text? }
rollup.sql: many (a: int4) -> { author_id: int8?, n: int8 }
second_key.sql: maybeOne (e: text) -> { id: int8, email: text }
self_join_nonkey.sql: many (id: int4) -> { id: int8 }
star.sql: maybeOne (id: int4) -> { id: int8, author_id: int8, title: text }
straight_join.sql: maybeOne (id: int8) -> { title: text, name: text }
subquery.sql: maybeOne (id: int4) -> { id: int8, title: text }
two_subqueries.sql: maybeOne (id: int4) -> { title: text, name: text }
two_withs.sql: maybeOne (id: int4) -> { id: int8, title: text }
union_all.sql: many (id: int4) -> { id: int8 }
view.sql: maybeOne (id: int8) -> { id: int8, title: text }
view_column_list.sql: many (id: int8) -> { post_id: int8, headline: text }
view_group_by.sql: maybeOne (a: int8) -> { author_id: int8, n: int8 }
view_join.sql: maybeOne (id: int8) -> { id: int8, title: text, name: text }
view_join_many.sql: many (id: int8) -> { id: int8, tag: text }
view_merged.sql: maybeOne (id: int8) -> { id: int8, title: text }
view_of_view.sql: maybeOne (id: int8) -> { id: int8, title: text }
view_swapped_columns.sql: many (id: text) -> { title: int8, id: text }
view_temptable.sql: maybeOne (id: int8) -> { id: int8, title: text }
window_inside.sql: maybeOne (id: int4) -> { id: int8, rn: int8 }
with_joined.sql: maybeOne (u: int4, id: int4) -> { title: text, name: text }
with_query.sql: maybeOne (id: int4) -> { id: int8, title: text }
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/expression.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select id + 0 as id, title from posts) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/filtered_inside.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select id, title from posts where author_id = :a) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/group_by.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select author_id, count(*) as n from posts group by author_id) s where s.author_id = :a
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/group_by_ordinal.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select author_id, count(*) as n from posts group by 1) s where s.author_id = :a
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/group_key_hidden.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select author_id, count(*) as n from posts group by author_id) s where s.n = :n
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/join_double_column.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select u.name from scores s join users u on u.id = s.score where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/join_many.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select p.id, t.tag from posts p join tags t on t.post_id = p.id) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/join_on_key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select p.title, u.name from posts p join users u on u.id = p.author_id where p.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/join_pinned.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select p.id, p.title, u.name from posts p join users u on u.id = p.author_id) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/join_text_column.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select p.title, u.name from posts p join users u on u.code = p.title where p.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/join_unpinned.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select p.title, u.name from posts p join users u on u.id = p.author_id where u.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/joined_on_key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select p.title, s.name from posts p join (select id, name from users) s on s.id = p.author_id where p.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/key_double_arithmetic.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select id from users where id = :x + 0e0
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/key_double_cast.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select id from users where id = cast(:x as double)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select id from users where id = cast('9007199254740992' as double)
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/key_double_function.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select id from users where id = abs(cast(:x as double))
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/key_double_literal.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select id from users where id = 9007199254740993e0
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/key_dropped.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select title from posts) s where s.title = :t
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/key_exact_function.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select id from users where id = abs(:x)
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/key_inside.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select id, title from posts where id = :id) s
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/lateral_pinned.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select u.name, s.title from users u join lateral (select id, title from posts where author_id = u.id) s where u.id = :u and s.id = :p
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/lateral_source.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select s.id from users u join lateral (select p.id, u.id as uid from posts p) s where u.id = s.uid and s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/left_join_many.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select u.id from users u left join posts p on p.author_id = u.id) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/left_join_on_key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select p.title, u.name from posts p left join users u on u.id = p.author_id where p.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/left_join_pinned.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select p.id, p.title, u.name from posts p left join users u on u.id = p.author_id) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/limit_inside.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select id, title from posts order by id limit 10 offset 5) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/nested.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select * from (select id, title from posts) a) b where b.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/not_a_key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select s.id, u.email from (select id, author_id from posts) s join users u on u.id = s.author_id where u.email = :e
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/null_extended_side.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select p.id, u.name from users u left join posts p on p.author_id = u.id) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/recursive.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
with recursive r (id, depth) as (select id, 0 from posts union all select id, depth + 1 from r where depth < 2) select id from r where r.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/renamed.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select id as post_id, title from posts) s where s.post_id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/right_join_on_key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select p.title, u.name from users u right join posts p on u.id = p.author_id where p.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/rollup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select author_id, count(*) as n from posts group by author_id with rollup) s where s.author_id = :a
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/second_key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select id, email from users) s where s.email = :e
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/self_join_nonkey.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select a.id from posts a join posts b on b.author_id = a.author_id) s where s.id = :id
17 changes: 17 additions & 0 deletions oracle/cases/mysql_subquery_keys/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- A derived table, a WITH query or a view is pinned to one row by a unique key of its rows, as a
-- table is by its index: a key of a FROM item the select list keeps unchanged, every other item
-- pinned to one row per row of it, or the select list's GROUP BY or DISTINCT. Joins pin a table
-- through another table's key. Anything that can repeat a row leaves no key.
create table users (id bigint primary key, email varchar(200) not null unique, name varchar(200) not null, code varchar(20) unique);
create table posts (id bigint primary key, author_id bigint not null, title text not null);
create table tags (post_id bigint not null, tag varchar(100) not null, primary key (post_id, tag));
create view public_posts as select id, title from posts;
create algorithm = temptable view public_posts_temp as select id, title from posts;
create algorithm = merge view public_posts_merged as select id, title from posts;
create view renamed_posts (post_id, headline) as select id, title from posts;
create view post_authors as select p.id, p.title, u.name from posts p join users u on u.id = p.author_id;
create view author_counts as select author_id, count(*) as n from posts group by author_id;
create view recent_posts as select * from public_posts where id > 10;
create view post_tags as select p.id, t.tag from posts p join tags t on t.post_id = p.id;
create table scores (id bigint primary key, score double not null, rate double not null unique);
create view swapped (title, id) as select id, title from posts;
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/star.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select * from posts) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/straight_join.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select p.title, u.name from posts p straight_join users u on u.id = p.author_id where p.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/subquery.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select id, title from posts) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/two_subqueries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select a.title, b.name from (select id, title, author_id from posts) a join (select id, name from users) b on b.id = a.author_id where a.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/two_withs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
with a as (select id, title from posts), b as (select * from a) select * from b where b.id = :id
Empty file.
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/union_all.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select id from posts union all select id from posts) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/view.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from public_posts where id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/view_column_list.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from renamed_posts where post_id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/view_group_by.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from author_counts where author_id = :a
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/view_join.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from post_authors where id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/view_join_many.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from post_tags where id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/view_merged.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from public_posts_merged where id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/view_of_view.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from recent_posts where id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/view_swapped_columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from swapped where id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/view_temptable.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from public_posts_temp where id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/window_inside.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from (select id, row_number() over (order by id) as rn from posts) s where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/with_joined.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
with s as (select id, title from posts) select s.title, u.name from s join users u on u.id = :u where s.id = :id
1 change: 1 addition & 0 deletions oracle/cases/mysql_subquery_keys/with_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
with s as (select id, title from posts) select * from s where s.id = :id
Loading
Loading
0