Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MySQL techtalk

MySQL techtalk

Openminds - 13 februari 2014

Bernard Grymonpon

February 13, 2014
Tweet

More Decks by Bernard Grymonpon

Other Decks in Science

Transcript

  1. MySQL • RDBMS • Open Source • 2de meest gebruikte

    OS RDBMS • SQL compliant (ANSI SQL 99 & more) Friday 14 February 14
  2. ’94 tot ’08 • begin ’94: MySQL AB • 23

    mei ’95: eerste release • v3.19 (eind ’96) tot v3.23 (eind ‘01) • v4.x (’02 tot ’04) • v5.0.x (’05 tot ...) Friday 14 February 14
  3. Sun-era • 2008 - Sun microsystems koopt MySQL AB •

    5.1.x releases begonnen in ’08 Friday 14 February 14
  4. Oracle • 27 januari 2010: Oracle koopt Sun • Anti-concurrentie

    • Tot 2015: dual licenced Friday 14 February 14
  5. Meer oracle • Niet alle changes komen nog beschikbaar •

    Code-reshuffle tussen 5.5 en 5.6 • InnoDB gegijzeld Friday 14 February 14
  6. InnoDB • Transacties • References / foreign keys • Row

    level locking • Inserts/updates Friday 14 February 14
  7. Data manipuleren • Insert into ... • Update ... •

    Delete from ... • ... from infile ... • Truncate Friday 14 February 14
  8. Data ophalen • select from ... • ... join ...

    • ... where ... • ... group by ... • ... having ... • ... order ... Friday 14 February 14
  9. idx_a: where... • a = const • a < const,

    a > const, a <= const, a >= const • a between const and const2 Friday 14 February 14
  10. idx_a_b • gecombineerde index • eerst a (prefix), dan b

    • where a = const and b = const • where a = const and b < const • where a between and b = const Friday 14 February 14
  11. Cardinaliteit • Mate van variatie • Mate van sterkte van

    de filter • Hoger is beter Friday 14 February 14
  12. mysql> desc City; +-------------+----------+------+-----+---------+----------------+ | Field | Type | Null

    | Key | Default | Extra | +-------------+----------+------+-----+---------+----------------+ | ID | int(11) | NO | PRI | NULL | auto_increment | | Name | char(35) | NO | | | | | CountryCode | char(3) | NO | MUL | | | | District | char(20) | NO | | | | | Population | int(11) | NO | | 0 | | +-------------+----------+------+-----+---------+----------------+ 5 rows in set (0.00 sec) Friday 14 February 14
  13. mysql> explain select * from City where Population < 27000\G

    *************************** 1. row *************************** id: 1 select_type: SIMPLE table: City type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 4188 Extra: Using where 1 row in set (0.00 sec) Friday 14 February 14
  14. mysql> create index idx_1 on City(Population); Query OK, 0 rows

    affected (0.03 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> show indexes from City\G ...<snip>... *************************** 3. row *************************** Table: city Non_unique: 1 Key_name: idx_1 Seq_in_index: 1 Column_name: Population Collation: A Cardinality: 4188 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: Index_comment: 3 rows in set (0.00 sec) Friday 14 February 14
  15. mysql> explain select * from City where Population < 27000\G

    *************************** 1. row *************************** id: 1 select_type: SIMPLE table: City type: range possible_keys: idx_1 key: idx_1 key_len: 4 ref: NULL rows: 64 Extra: Using index condition 1 row in set (0.00 sec) Friday 14 February 14
  16. mysql> explain select * from City where Name = "Gent"\G

    *************************** 1. row *************************** rows: 4188 Extra: Using where 1 row in set (0.00 sec) mysql> create index Name on City (Name); Query OK, 0 rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> explain select * from City where Name = "Gent"\G *************************** 1. row *************************** table: City type: ref possible_keys: Name key: Name key_len: 35 ref: const rows: 1 Extra: Using index condition 1 row in set (0.00 sec) Friday 14 February 14
  17. mysql> create index Population on City (Population); Query OK, 0

    rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0 Friday 14 February 14
  18. mysql> explain select * from City where Name = "Gent"

    and Population < 27000\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: City type: ref possible_keys: Name,Population key: Name key_len: 35 ref: const rows: 1 Extra: Using index condition; Using where 1 row in set (0.00 sec) Friday 14 February 14
  19. mysql> explain select * from City where Name like "G%"

    and Population < 27000\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: City type: range possible_keys: Name,Population key: Population key_len: 4 ref: NULL rows: 64 Extra: Using index condition; Using where 1 row in set (0.00 sec) Friday 14 February 14
  20. mysql> create index NameAndPopulation on City(Name,Population); Query OK, 0 rows

    affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> explain select * from City where Name like "G%" and Population < 27000\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: City type: range possible_keys: Name,Population,NameAndPopulation key: Population key_len: 4 ref: NULL rows: 64 Extra: Using index condition; Using where 1 row in set (0.00 sec) Friday 14 February 14
  21. mysql> explain select * from City where Name like "Ge%"

    and Population < 27000\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: City type: range possible_keys: Name,Population,NameAndPopulation key: NameAndPopulation key_len: 39 ref: NULL rows: 16 Extra: Using index condition 1 row in set (0.00 sec) Friday 14 February 14
  22. • (Inner) join • Outer join • Left join, right

    join • ... Friday 14 February 14
  23. SELECT * FROM employee FULL OUTER JOIN department ON employee.DepartmentID

    = department.DepartmentID Friday 14 February 14
  24. SELECT * FROM employee FULL OUTER JOIN department ON employee.DepartmentID

    = department.DepartmentID Friday 14 February 14
  25. SELECT * FROM employee LEFT OUTER JOIN department ON employee.DepartmentID

    = department.DepartmentID Friday 14 February 14
  26. SELECT * FROM employee LEFT OUTER JOIN department ON employee.DepartmentID

    = department.DepartmentID Friday 14 February 14
  27. Charsets • latin1 was lang default • utf8 • SET

    NAMES utf8; Friday 14 February 14
  28. select * from posts where category like ‘%,52,%’ or category

    like ’52,%’ or category like ‘%,52’; Friday 14 February 14
  29. select max(id) from posts; ... ... php-code ... select *

    from posts where id in (34,65,78,123,453); Friday 14 February 14