From db20f182e2fa6fbffbc194ad54913d1a35c8b781 Mon Sep 17 00:00:00 2001 From: wenzhi <732903873@qq.com> Date: Wed, 20 Feb 2019 21:27:10 +0800 Subject: [PATCH] Bats Test SQL Rewrite and Add golden file --- test/env.bats | 6 ++ test/fixture/test_Check_Soar_Delimiter.golden | 40 +++++++++ .../test_Check_Soar_Max_Column_Count.golden | 56 ++++++++++++ .../test_Check_Soar_SQL_Fingerprint.golden | 85 +++++++++++++++++++ ..._Check_Soar_SQL_Rewrite_Alwaystrue_.golden | 1 + ...t_Check_Soar_SQL_Rewrite_Countstar_.golden | 1 + ...t_Check_Soar_SQL_Rewrite_Delimiter_.golden | 1 + ...heck_Soar_SQL_Rewrite_Distinctstar_.golden | 1 + ..._Check_Soar_SQL_Rewrite_Dml2select_.golden | 1 + ..._Check_Soar_SQL_Rewrite_Dmlorderby_.golden | 1 + ...test_Check_Soar_SQL_Rewrite_Having_.golden | 1 + ..._Check_Soar_SQL_Rewrite_Mergealter_.golden | 1 + .../test_Check_Soar_SQL_Rewrite_Or2in_.golden | 1 + ...Check_Soar_SQL_Rewrite_Orderbynull_.golden | 1 + ...eck_Soar_SQL_Rewrite_Rmparenthesis_.golden | 1 + ...st_Check_Soar_SQL_Rewrite_Standard_.golden | 1 + ...heck_Soar_SQL_Rewrite_Star2columns_.golden | 1 + ...st_Check_Soar_SQL_Rewrite_Truncate_.golden | 1 + ...st_Check_Soar_SQL_Rewrite_Unionall_.golden | 1 + ...Check_Soar_SQL_pretty_And_Compress_.golden | 85 +++++++++++++++++++ 20 files changed, 287 insertions(+) create mode 100644 test/fixture/test_Check_Soar_Delimiter.golden create mode 100644 test/fixture/test_Check_Soar_Max_Column_Count.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Fingerprint.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Alwaystrue_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Countstar_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Delimiter_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Distinctstar_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Dml2select_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Dmlorderby_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Having_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Mergealter_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Or2in_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Orderbynull_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Rmparenthesis_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Standard_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Star2columns_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Truncate_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_Rewrite_Unionall_.golden create mode 100644 test/fixture/test_Check_Soar_SQL_pretty_And_Compress_.golden diff --git a/test/env.bats b/test/env.bats index f14758e..81da2d5 100644 --- a/test/env.bats +++ b/test/env.bats @@ -5,12 +5,18 @@ load test_helper @test "Simple Query Optimizer" { ${SOAR_BIN_ENV} -query "select * from film where length > 120" | grep -v "散粒度" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden run golden_diff + echo "$output" [ $status -eq 0 ] } @test "Run all test cases" { ${SOAR_BIN} -list-test-sqls | ${SOAR_BIN_ENV} | grep -v "散粒度" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden run golden_diff + echo "$output" [ $status -eq 0 ] } +@test "Check dial timeout" { + run timeout 1 ${SOAR_BIN} -test-dsn "1.1.1.1" -check-config + [ $status -eq 124 ] +} diff --git a/test/fixture/test_Check_Soar_Delimiter.golden b/test/fixture/test_Check_Soar_Delimiter.golden new file mode 100644 index 0000000..029ff90 --- /dev/null +++ b/test/fixture/test_Check_Soar_Delimiter.golden @@ -0,0 +1,40 @@ +# Query: 8093354EDF76BFDA + +★ ★ ★ ★ ☆ 80分 + +```sql + +SELECT + b +FROM + c +``` + +## 最外层 SELECT 未指定 WHERE 条件 + +* **Item:** CLA.001 + +* **Severity:** L4 + +* **Content:** SELECT 语句没有 WHERE 子句,可能检查比预期更多的行(全表扫描)。对于 SELECT COUNT(\*) 类型的请求如果不要求精度,建议使用 SHOW TABLE STATUS 或 EXPLAIN 替代。 + +# Query: DD1A4C78C3479C1E + +★ ★ ★ ★ ☆ 80分 + +```sql + +SELECT + a +FROM + b +``` + +## 最外层 SELECT 未指定 WHERE 条件 + +* **Item:** CLA.001 + +* **Severity:** L4 + +* **Content:** SELECT 语句没有 WHERE 子句,可能检查比预期更多的行(全表扫描)。对于 SELECT COUNT(\*) 类型的请求如果不要求精度,建议使用 SHOW TABLE STATUS 或 EXPLAIN 替代。 + diff --git a/test/fixture/test_Check_Soar_Max_Column_Count.golden b/test/fixture/test_Check_Soar_Max_Column_Count.golden new file mode 100644 index 0000000..299b793 --- /dev/null +++ b/test/fixture/test_Check_Soar_Max_Column_Count.golden @@ -0,0 +1,56 @@ +# Query: 7EC60923DD614DF2 + +★ ☆ ☆ ☆ ☆ 30分 + +```sql +create table a (a int, b int, c int, d int) +``` + +## 建议为表添加注释 + +* **Item:** CLA.011 + +* **Severity:** L1 + +* **Content:** 为表添加注释能够使得表的意义更明确,从而为日后的维护带来极大的便利。 + +## 请为列添加默认值 + +* **Item:** COL.004 + +* **Severity:** L1 + +* **Content:** 请为列添加默认值,如果是 ALTER 操作,请不要忘记将原字段的默认值写上。字段无默认值,当表较大时无法在线变更表结构。 + +## 列未添加注释 + +* **Item:** COL.005 + +* **Severity:** L1 + +* **Content:** 建议对表中每个列添加注释,来明确每个列在表中的含义及作用。 + +## 表中包含有太多的列 + +* **Item:** COL.006 + +* **Severity:** L3 + +* **Content:** 表中包含有太多的列 + +## 未指定主键或主键非 int 或 bigint + +* **Item:** KEY.007 + +* **Severity:** L4 + +* **Content:** 未指定主键或主键非 int 或 bigint,建议将主键设置为 int unsigned 或 bigint unsigned。 + +## 请为表选择合适的存储引擎 + +* **Item:** TBL.002 + +* **Severity:** L4 + +* **Content:** 建表或修改表的存储引擎时建议使用推荐的存储引擎,如:innodb + diff --git a/test/fixture/test_Check_Soar_SQL_Fingerprint.golden b/test/fixture/test_Check_Soar_SQL_Fingerprint.golden new file mode 100644 index 0000000..10f2fca --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Fingerprint.golden @@ -0,0 +1,85 @@ +select * from film where length = ? +select * from film where length is null +select * from film having title = ? +select * from sakila.film where length >= ? +select * from sakila.film where length >= ? +select * from film where length between ? and ? +select * from film where title like ? +select * from film where title is not null +select * from film where length = ? and title = ? +select * from film where length > ? and title = ? +select * from film where length > ? and language_id < ? and title = ? +select * from film where length > ? and language_id < ? +select release_year, sum(length) from film where length = ? and language_id = ? group by release_year +select release_year, sum(length) from film where length >= ? group by release_year +select release_year, language_id, sum(length) from film group by release_year, language_id +select release_year, sum(length) from film where length = ? group by language_id) +select release_year, sum(film_id) from film group by release_year +select * from address group by address,district +select title from film where abs(language_id) = ? group by title +select language_id from film where length = ? group by release_year order by language_id +select release_year from film where length = ? group by release_year order by release_year +select * from film where length = ? order by release_year, language_id desc +select release_year from film where length = ? group by release_year order by release_year limit ? +select * from film where length = ? order by release_year limit ? +select * from film order by release_year limit ? +select film_id from film order by release_year limit ? +select * from film where length > ? order by length limit ? +select * from film where length < ? order by length limit ? +select * from customer where address_id in(?+) order by last_name +select * from film where release_year = ? and length != ? order by title +select title from film where release_year = ? +select title, replacement_cost from film where language_id = ? and length = ? +select title from film where language_id > ? and length > ? +select * from film where length = ? and title = ? order by release_year +select * from film where length > ? and title = ? order by release_year +select * from film where length > ? order by release_year +select * from city a inner join country b on a.country_id=b.country_id +select * from city a left join country b on a.country_id=b.country_id +select * from city a right join country b on a.country_id=b.country_id +select * from city a left join country b on a.country_id=b.country_id where b.last_update is null +select * from city a right join country b on a.country_id=b.country_id where a.last_update is null +select * from city a left join country b on a.country_id=b.country_id union select * from city a right join country b on a.country_id=b.country_id +select * from city a right join country b on a.country_id=b.country_id where a.last_update is null union select * from city a left join country b on a.country_id=b.country_id where b.last_update is null +select country_id, last_update from city natural join country +select country_id, last_update from city natural left join country +select country_id, last_update from city natural right join country +select a.country_id, a.last_update from city a straight_join country b on a.country_id=b.country_id +select a.address, a.postal_code from sakila.address a where a.city_id in(?+) +select city from( select city_id from city where city = ? order by last_update desc limit ?, ?) i join city on (i.city_id = city.city_id) join country on (country.country_id = city.country_id) order by city desc +delete city, country from city inner join country using (country_id) where city.city_id = ? +delete city from city left join country on city.country_id = country.country_id where country.country is null +delete a1, a2 from city as a1 inner join country as a2 where a1.country_id=a2.country_id +delete from a1, a2 using city as a1 inner join country as a2 where a1.country_id=a2.country_id +delete from film where length > ? +update city inner join country using(country_id) set city.city = ?, city.last_update = ?, country.country = ? where city.city_id=? +update city inner join country on city.country_id = country.country_id inner join address on city.city_id = address.city_id set city.city = ?, city.last_update = ?, country.country = ? where city.city_id=? +update city, country set city.city = ?, city.last_update = ?, country.country = ? where city.country_id = country.country_id and city.city_id=? +update film set length = ? where language_id = ? +insert into city (country_id) select country_id from country +insert into city (country_id) values(?+) +insert into city (country_id) values(?+) +insert into city (country_id) select ? from dual +replace into city (country_id) select country_id from country +replace into city (country_id) values(?+) +replace into city (country_id) values(?+) +replace into city (country_id) select ? from dual +select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from ( select film_id from film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film +select * from film where language_id = (select language_id from language limit ?) +select * from city i left join country o on i.city_id=o.country_id union select * from city i right join country o on i.city_id=o.country_id +select * from (select * from actor where last_update=? and last_name=?) t where last_update=? and last_name=? group by first_name +select * from city i left join country o on i.city_id=o.country_id union select * from city i right join country o on i.city_id=o.country_id +select * from city i left join country o on i.city_id=o.country_id where o.country_id is null union select * from city i right join country o on i.city_id=o.country_id where i.city_id is null +select first_name,last_name,email from customer straight_join address on customer.address_id=address.address_id +select id,name from (select address from customer_list where sid=? order by phone limit ?,?) a join customer_list l on (a.address=l.address) join city c on (c.city=l.city) order by phone desc +select * from film where date(last_update)=? +select last_update from film group by date(last_update) +select last_update from film order by date(last_update) +select description from film where description in(?+) group by description +alter table address add index idx_city_id(city_id) +alter table inventory add index `idx_store_film` (`store_id`,`film_id`) +alter table inventory add index `idx_store_film` (`store_id`,`film_id`),add index `idx_store_film` (`store_id`,`film_id`),add index `idx_store_film` (`store_id`,`film_id`) +select date_format(t.last_update, ?), count(distinct (t.city)) from city t where t.last_update > ? and t.city like ? and t.city = ? group by date_format(t.last_update, ?) order by date_format(t.last_update, ?) +create table hello.t (id int unsigned) +select * from tb where data >= ? +alter table tb alter column id drop default diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Alwaystrue_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Alwaystrue_.golden new file mode 100644 index 0000000..334a6ac --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Alwaystrue_.golden @@ -0,0 +1 @@ +select count(col) from tbl where (a = 'b') diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Countstar_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Countstar_.golden new file mode 100644 index 0000000..189193c --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Countstar_.golden @@ -0,0 +1 @@ +select count(*) from tbl group by 1 diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Delimiter_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Delimiter_.golden new file mode 100644 index 0000000..d58de2d --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Delimiter_.golden @@ -0,0 +1 @@ +use sakila; diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Distinctstar_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Distinctstar_.golden new file mode 100644 index 0000000..b02b25c --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Distinctstar_.golden @@ -0,0 +1 @@ +SELECT * FROM film diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Dml2select_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Dml2select_.golden new file mode 100644 index 0000000..4c93bb0 --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Dml2select_.golden @@ -0,0 +1 @@ +select * from film where length > 100 diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Dmlorderby_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Dmlorderby_.golden new file mode 100644 index 0000000..e0c10c5 --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Dmlorderby_.golden @@ -0,0 +1 @@ +delete from tbl where col1 = 1 diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Having_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Having_.golden new file mode 100644 index 0000000..7f39569 --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Having_.golden @@ -0,0 +1 @@ +select state, COUNT(*) from Drivers where state in ('GA', 'TX') group by state order by state asc diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Mergealter_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Mergealter_.golden new file mode 100644 index 0000000..fd5900e --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Mergealter_.golden @@ -0,0 +1 @@ +ALTER TABLE `t2` DROP COLUMN c, DROP COLUMN d ; diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Or2in_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Or2in_.golden new file mode 100644 index 0000000..db9fdb5 --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Or2in_.golden @@ -0,0 +1 @@ +select country_id from city where (col2 in (1, 2)) or col1 in (1, 3) diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Orderbynull_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Orderbynull_.golden new file mode 100644 index 0000000..4f5cd76 --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Orderbynull_.golden @@ -0,0 +1 @@ +select sum(col1) from tbl group by col order by null diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Rmparenthesis_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Rmparenthesis_.golden new file mode 100644 index 0000000..40e7cb1 --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Rmparenthesis_.golden @@ -0,0 +1 @@ +select col from a where col = 1 diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Standard_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Standard_.golden new file mode 100644 index 0000000..38834a1 --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Standard_.golden @@ -0,0 +1 @@ +select sum(col1) from tbl group by 1 diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Star2columns_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Star2columns_.golden new file mode 100644 index 0000000..ddcbc10 --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Star2columns_.golden @@ -0,0 +1 @@ +select film_id, title, description, release_year, language_id, original_language_id, rental_duration, rental_rate, length, replacement_cost, rating, special_features, last_update from film where length > 120 diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Truncate_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Truncate_.golden new file mode 100644 index 0000000..dbc6253 --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Truncate_.golden @@ -0,0 +1 @@ +truncate table tbl diff --git a/test/fixture/test_Check_Soar_SQL_Rewrite_Unionall_.golden b/test/fixture/test_Check_Soar_SQL_Rewrite_Unionall_.golden new file mode 100644 index 0000000..6fd7669 --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_Rewrite_Unionall_.golden @@ -0,0 +1 @@ +select country_id from city union all select country_id from country diff --git a/test/fixture/test_Check_Soar_SQL_pretty_And_Compress_.golden b/test/fixture/test_Check_Soar_SQL_pretty_And_Compress_.golden new file mode 100644 index 0000000..8916aef --- /dev/null +++ b/test/fixture/test_Check_Soar_SQL_pretty_And_Compress_.golden @@ -0,0 +1,85 @@ +SELECT * FROM film WHERE LENGTH = 86; +SELECT * FROM film WHERE LENGTH IS NULL; +SELECT * FROM film HAVING title = 'abc'; +SELECT * FROM sakila. film WHERE LENGTH >= 60; +SELECT * FROM sakila. film WHERE LENGTH >= '60'; +SELECT * FROM film WHERE LENGTH BETWEEN 60 AND 84; +SELECT * FROM film WHERE title LIKE 'AIR%'; +SELECT * FROM film WHERE title IS NOT NULL; +SELECT * FROM film WHERE LENGTH = 114 AND title = 'ALABAMA DEVIL'; +SELECT * FROM film WHERE LENGTH > 100 AND title = 'ALABAMA DEVIL'; +SELECT * FROM film WHERE LENGTH > 100 AND language_id < 10 AND title = 'xyz'; +SELECT * FROM film WHERE LENGTH > 100 AND language_id < 10; +SELECT release_year, SUM( LENGTH) FROM film WHERE LENGTH = 123 AND language_id = 1 GROUP BY release_year; +SELECT release_year, SUM( LENGTH) FROM film WHERE LENGTH >= 123 GROUP BY release_year; +SELECT release_year, language_id, SUM( LENGTH) FROM film GROUP BY release_year, language_id; +SELECT release_year, SUM( LENGTH) FROM film WHERE LENGTH = 123 GROUP BY release_year, (LENGTH+ language_id); +SELECT release_year, SUM( film_id) FROM film GROUP BY release_year; +SELECT * FROM address GROUP BY address, district; +SELECT title FROM film WHERE ABS( language_id) = 3 GROUP BY title; +SELECT language_id FROM film WHERE LENGTH = 123 GROUP BY release_year ORDER BY language_id; +SELECT release_year FROM film WHERE LENGTH = 123 GROUP BY release_year ORDER BY release_year; +SELECT * FROM film WHERE LENGTH = 123 ORDER BY release_year ASC, language_id DESC; +SELECT release_year FROM film WHERE LENGTH = 123 GROUP BY release_year ORDER BY release_year LIMIT 10; +SELECT * FROM film WHERE LENGTH = 123 ORDER BY release_year LIMIT 10; +SELECT * FROM film ORDER BY release_year LIMIT 10; +SELECT film_id FROM film ORDER BY release_year LIMIT 10; +SELECT * FROM film WHERE LENGTH > 100 ORDER BY LENGTH LIMIT 10; +SELECT * FROM film WHERE LENGTH < 100 ORDER BY LENGTH LIMIT 10; +SELECT * FROM customer WHERE address_id in (224, 510) ORDER BY last_name; +SELECT * FROM film WHERE release_year = 2016 AND LENGTH != 1 ORDER BY title; +SELECT title FROM film WHERE release_year = 1995; +SELECT title, replacement_cost FROM film WHERE language_id = 5 AND LENGTH = 70; +SELECT title FROM film WHERE language_id > 5 AND LENGTH > 70; +SELECT * FROM film WHERE LENGTH = 100 AND title = 'xyz' ORDER BY release_year; +SELECT * FROM film WHERE LENGTH > 100 AND title = 'xyz' ORDER BY release_year; +SELECT * FROM film WHERE LENGTH > 100 ORDER BY release_year; +SELECT * FROM city a INNER JOIN country b ON a. country_id= b. country_id; +SELECT * FROM city a LEFT JOIN country b ON a. country_id= b. country_id; +SELECT * FROM city a RIGHT JOIN country b ON a. country_id= b. country_id; +SELECT * FROM city a LEFT JOIN country b ON a. country_id= b. country_id WHERE b. last_update IS NULL; +SELECT * FROM city a RIGHT JOIN country b ON a. country_id= b. country_id WHERE a. last_update IS NULL; +SELECT * FROM city a LEFT JOIN country b ON a. country_id= b. country_id UNION SELECT * FROM city a RIGHT JOIN country b ON a. country_id= b. country_id; +SELECT * FROM city a RIGHT JOIN country b ON a. country_id= b. country_id WHERE a. last_update IS NULL UNION SELECT * FROM city a LEFT JOIN country b ON a. country_id= b. country_id WHERE b. last_update IS NULL; +SELECT country_id, last_update FROM city NATURAL JOIN country; +SELECT country_id, last_update FROM city NATURAL LEFT JOIN country; +SELECT country_id, last_update FROM city NATURAL RIGHT JOIN country; +SELECT a. country_id, a. last_update FROM city a STRAIGHT_JOIN country b ON a. country_id= b. country_id; +SELECT a. address, a. postal_code FROM sakila. address a WHERE a. city_id IN ( SELECT c. city_id FROM sakila. city c); +SELECT city FROM( SELECT city_id FROM city WHERE city = "A Corua (La Corua)" ORDER BY last_update DESC LIMIT 50, 10) I JOIN city ON (I. city_id = city. city_id) JOIN country ON (country. country_id = city. country_id) ORDER BY city DESC; +DELETE city, country FROM city INNER JOIN country using (country_id) WHERE city. city_id = 1; +DELETE city FROM city LEFT JOIN country ON city. country_id = country. country_id WHERE country. country IS NULL; +DELETE a1, a2 FROM city AS a1 INNER JOIN country AS a2 WHERE a1. country_id= a2. country_id; +DELETE FROM a1, a2 USING city AS a1 INNER JOIN country AS a2 WHERE a1. country_id= a2. country_id; +DELETE FROM film WHERE LENGTH > 100; +UPDATE city INNER JOIN country USING( country_id) SET city. city = 'Abha', city. last_update = '2006-02-15 04:45:25', country. country = 'Afghanistan' WHERE city. city_id= 10; +UPDATE city INNER JOIN country ON city. country_id = country. country_id INNER JOIN address ON city. city_id = address. city_id SET city. city = 'Abha', city. last_update = '2006-02-15 04:45:25', country. country = 'Afghanistan' WHERE city. city_id= 10; +UPDATE city, country SET city. city = 'Abha', city. last_update = '2006-02-15 04:45:25', country. country = 'Afghanistan' WHERE city. country_id = country. country_id AND city. city_id= 10; +UPDATE film SET LENGTH = 10 WHERE language_id = 20; +INSERT INTO city (country_id) SELECT country_id FROM country; +INSERT INTO city (country_id) VALUES (1), (2), (3); +INSERT INTO city (country_id) VALUES (10); +INSERT INTO city (country_id) SELECT 10 FROM DUAL; +REPLACE INTO city (country_id) SELECT country_id FROM country; +REPLACE INTO city (country_id) VALUES (1), (2), (3); +REPLACE INTO city (country_id) VALUES (10); +REPLACE INTO city (country_id) SELECT 10 FROM DUAL; +SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM ( SELECT film_id FROM film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film ) film; +SELECT * FROM film WHERE language_id = ( SELECT language_id FROM language LIMIT 1); +SELECT * FROM city i LEFT JOIN country o ON i. city_id= o. country_id UNION SELECT * FROM city i RIGHT JOIN country o ON i. city_id= o. country_id; +SELECT * FROM ( SELECT * FROM actor WHERE last_update= '2006-02-15 04:34:33' AND last_name= 'CHASE' ) t WHERE last_update= '2006-02-15 04:34:33' AND last_name= 'CHASE' GROUP BY first_name; +SELECT * FROM city i LEFT JOIN country o ON i. city_id= o. country_id UNION SELECT * FROM city i RIGHT JOIN country o ON i. city_id= o. country_id; +SELECT * FROM city i LEFT JOIN country o ON i. city_id= o. country_id WHERE o. country_id is null UNION SELECT * FROM city i RIGHT JOIN country o ON i. city_id= o. country_id WHERE i. city_id is null; +SELECT first_name, last_name, email FROM customer STRAIGHT_JOIN address ON customer. address_id= address. address_id; +SELECT ID, name FROM ( SELECT address FROM customer_list WHERE SID= 1 ORDER BY phone LIMIT 50, 10) a JOIN customer_list l ON (a. address= l. address) JOIN city c ON (c. city= l. city) ORDER BY phone desc; +SELECT * FROM film WHERE DATE( last_update) = '2006-02-15'; +SELECT last_update FROM film GROUP BY DATE( last_update); +SELECT last_update FROM film ORDER BY DATE( last_update); +SELECT description FROM film WHERE description IN( 'NEWS', 'asd' ) GROUP BY description; +ALTER TABLE address ADD index idx_city_id( city_id); +ALTER TABLE inventory ADD index `idx_store_film` ( `store_id`, `film_id`); +ALTER TABLE inventory ADD index `idx_store_film` ( `store_id`, `film_id`), ADD index `idx_store_film` ( `store_id`, `film_id`), ADD index `idx_store_film` ( `store_id`, `film_id`); +SELECT DATE_FORMAT( t. last_update, '%Y-%m-%d' ), COUNT( DISTINCT ( t. city)) FROM city t WHERE t. last_update > '2018-10-22 00:00:00' AND t. city LIKE '%Chrome%' AND t. city = 'eip' GROUP BY DATE_FORMAT( t. last_update, '%Y-%m-%d' ) ORDER BY DATE_FORMAT( t. last_update, '%Y-%m-%d' ); +create table hello. t (id int unsigned); +SELECT * FROM tb WHERE data >= ''; +ALTER TABLE tb alter column id DROP DEFAULT; -- GitLab