Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. When things go wrong: how to find SQL error Sveta Smirnova Principle Technical Support Engineer, Oracle.

Similar presentations


Presentation on theme: "1. When things go wrong: how to find SQL error Sveta Smirnova Principle Technical Support Engineer, Oracle."— Presentation transcript:

1 1

2 When things go wrong: how to find SQL error Sveta Smirnova Principle Technical Support Engineer, MySQL @ Oracle

3 3 What to do? Find the problem Fix it

4 4 How? There are several easy methods Today I am going to show them

5 5 Part 1. Simple cases How to find the cause How to fix it Best practices

6 6 Incorrect syntax Trivial, but still need to be considered Can fake queries with correct syntax Can be incorrect depending from SQL mode If dynamically created in application can be tricky to find

7 7 Incorrect syntax select * fro t1 where f1 in (1,2,1); select max (f1) from t1; Correct syntax: max(f1)‏ select * from t1 where "f1"=1; Works with SQL Mode ANSI_QUOTES only

8 8 Incorrect syntax Always get query in state which MySQL gets it –Use methods of your API to output query (echo, print etc.)‏ –Use MySQL general query log –Use MySQL Proxy to catch the query

9 9 Logical error Find query results of which are not correct first Try it using MySQL command line client If problem is repeatable analyse why this happens Fix it

10 10 If query works properly Usually noticeable in applications Go back 1 step, check if you inserted correct data Repeat previous suggestion until you find wrong logic Fix it

11 11 Cause found, what to do next? Typical cases which cause the problem with description how to fix

12 12 First try After finding query which causes the problem rewrite it so it works as expected Test if it really works as expected Use EXPLAIN EXTENDED to find query execution plan

13 13 DML query Convert DML query to SELECT –Examine which queries returns WHERE clause –Use EXPLAIN EXTENDED if needed Fix the query Be sure everything works fine

14 14 Query rewriting does not help Check MySQL server and client options Start test environment from default values (run mysqld -- no-defaults)‏ If problem is not repeatable anymore Add options like you have in production one-by-one until one which causes the problem found

15 15 Query rewriting does not help Try to remove indexes from tables affected Try to remove ORDER BY and GROUP BY clauses Try to simplify query as much as possible to see if easier one returns correct results

16 16 Query rewriting does not help Check if this is known MySQL bug or gotcha Check –http://bugs.mysql.com –https://support.oracle.com (paying customers only)‏ –These 2 URLs contain partially different bugs content! Apply workaround if exists

17 17 Problem is not repeatable with single thread Use SHOW PROCESSLIST to find queries running in parallel which block current query Use table INFORMATION_SCHEMA.PROCESSLIST if you need list of simultaneous queries ordered by one of parameters.

18 18 Problem is not repeatable with single thread Use SHOW ENGINE INNODB STATUS, InnoDB monitors and new INFORMATION_SCHEMA.INNODB_* tables to find information about parallel transactions Use general query log if above do not help Use your application means to find the problem

19 19 A lot of data Symptoms: –ERROR 1153 (08S01) at line 33: Got a packet bigger than 'max_allowed_packet' bytes –ERROR 1064 (42000) at line 33: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '000000000000000000000000000000000000000000000000000 00000000000000000000000000000' at line 2 Check value of max_allowed_packet Be sure it is set for both server and client

20 20 Timeouts Symptoms: –MySQL server has gone away –Lost connection to MySQL server at... First check error log to be sure this is not a crash Variables: –connect_timeout –interactive_timeout –net_read_timeout, net_write_timeout –wait_timeout

21 21 Best practices Always use error log Get same query as MySQL server gets it before start debugging Use general query log to find problematic queries Check options Use bug databases and google to find workaround in case of bug/gotcha

22 22 Best practices Try everything in development environment first –Attend «Sandbox» part of my next session Do backups regularly –Attend «MYSQL ENTERPRISE BACKUP» (364) session at 10.30 am Use option log_warnings=2 to have information about aborted connections in the error log file

23 23 Part 2. Complex things Crashes Problems repeatable only in production/high load Sandbox Best practices

24 24 ?

25 25 Thank you!

26 26

27 27 The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

28


Download ppt "1. When things go wrong: how to find SQL error Sveta Smirnova Principle Technical Support Engineer, Oracle."

Similar presentations


Ads by Google