Wednesday, March 13, 2013

xdebug

xdebug_start_trace('c:/data/fac.xt');

xdebug_stop_trace();
exit;


http://www.mytrip.com/index.php?debug_profile=1

profiler_enable_trigger =1

http://www.mytrip.com/webgrind

Sunday, January 27, 2013

mysql performance

Use Keyword - Explain 

EXPLAIN SELECT * FROM tbl_name WHERE 1 = 0

The output from EXPLAIN is:
+------------------+
| Comment |
+------------------+
| Impossible WHERE |
+------------------+


Normally, EXPLAIN returns more information than that, including information about the indexes that will be used to
scan tables, the types of joins that will be used, and estimates of the number of rows that will need to be scanned
from each table.


Compare columns that have the same type
Try to make indexed columns stand alone in comparisons
1.
Declare columns to be NOT NULL. This gives you faster processing and requires less storage. It will also
simplify queries sometimes because you don't need to check for NULL as a special case.

2.Use PROCEDURE ANALYSE(). If you have MySQL 3.23 or newer, run PROCEDURE ANALYSE() to see what it
tells you about the columns in your table:
SELECT * FROM tbl_name PROCEDURE ANALYSE()
SELECT * FROM tbl_name PROCEDURE ANALYSE(16,256)


3.Consider using ENUM columns. If you have a string column that contains only a limited number of distinct
values, consider converting it to an ENUM column. ENUM values can be processed quickly because they are
represented as numeric values internally

4.Use OPTIMIZE TABLE for tables that are subject to fragmentation. Tables that are modified a great deal,
particularly those that contain variable-length columns, are subject to fragmentation. Fragmentation is bad
because it leads to unused space in the disk blocks used to store your table. Over time, you must read more
blocks to get the valid rows, and performance is reduced. This is true for any table with variable-length
rows, but is particularly acute for BLOB columns because they can vary so much in size. Use of OPTIMIZE
TABLE on a regular basis helps keep performance on the table from degrading

5.·  Shorter SQL statements are faster than longer statements because they involve less parsing on the part of
the server and because they can be sent over the network from the client to the server more quickly.

6.Let MySQL insert default values for you; don't specify columns in INSERT statements that will be assigned
the default value anyway. On average, your statements will be shorter, reducing the number of characters
sent over the network to the server. In addition, because the statements contain fewer values, the server
does less parsing and value conversion.

Perform joins carefully


Perform joins carefully

Joining data from two tables in one query is a very powerful technique, particularly when combined with normalisation. However, if not done right - even by a small margin - you can incur a serious speed hit. To get good performance from your joins, follow these simple rules:
  • If two fields contain identical information in different tables, declare them with the same name and with the same type
  • Filter the query as best as you can, otherwise you can get a very large number of results. For example, joining just three tables of 50 rows each will produce 125,000 records (50x50x50), as MySQL will return every combination of the rows.
  • Remember that it is sometimes better to have a little data duplication in exchange for the chance to not have slow joins. If your goal is maximum speed, be prepared to break a few rules!
  • Try to use numbers as opposed to strings when comparing rows in joins - the last thing you want is thousands of strings being compared.
  • Avoid joining rows where you are comparing non-indexed fields

Spot slow queries





Delete Unwanted Logs Master Slave Log

PURGE BINARY LOGS BEFORE '2019-06-08 00:00:00';

folder /var/lib/mysql 






No Sleep Query Required

SELECT * FROM information_schema.processlist WHERE COMMAND LIKE 'query%' ORDER BY TIME DESC;

 

 

 

 Spot slow queries

Perhaps you didn't realise this, but simply by enabling one option in your MySQL configuration file, MySQL will keep a log of all the queries it considers slow (usually taking longer than ten seconds to execute), as well as how many rows the slow query returned.
To activate the slow query log, simply start up MySQL with the option --log-slow-queries = /var/log/wherever/you/want/it. You can optionally also use --log-long-format, which will cause MySQL to consider all queries that don't use indexes as slow queries - this can be a great help if you are trying to add indexes, but you are not sure where they are needed.

Select as little data as possible

1. Do nout use *
2. Use Limit keyword