Sql EXPLAIN and DESCRIBE

Sql EXPLAIN and DESCRIBE
Nikhil
Published on 2021-08-14 14:10:17

EXPLAIN Select query

An Explain infront of a select query shows you how the query will be executed. This way you to see if the query uses an index or if you could optimize your query by adding an index.

Example query:

explain select * from user join data on user.test = data.fk_user;

Example result:

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE user index test test 5 (null) 1 Using where; Using index
1 SIMPLE data ref fk_user fk_user 5 user.test 1 (null)

on type you see if an index was used. In the column possible_keys you see if the execution plan can choose from different indexes of if none exists. key tells you the acutal used index. key_len shows you the size in bytes for one index item. The lower this value is the more index items fit into the same memory size an they can be faster processed. rows shows you the expected number of rows the query needs to scan, the lower the better.

Section 16.2: DESCRIBE tablename;

DESCRIBE and EXPLAIN are synonyms. DESCRIBE on a tablename returns the definition of the columns. DESCRIBE tablename;

Exmple Result:

COLUMN_NAME COLUMN_TYPE IS_NULLABLE COLUMN_KEY COLUMN_DEFAULT EXTRA id int(11) NO PRI 0 auto_increment test varchar(255) YES (null)

Here you see the column names, followed by the columns type. It shows if null is allowed in the column and if the column uses an Index. the default value is also displayed and if the table contains any special behavior like an auto_increment.

ATutorialHub Related Guide

Comments (8)

Leave a Comment

Your email address will not be published. Required fields are marked*

User Comments

html tutorial comments

panduranga gupta

2021-07-05 07:03:13

good website for learning and help me a lot

html tutorial comments

raju

2021-09-25 14:58:47

The awsome website i am looking like for a long time, good work atutorialhub team keep doing

html tutorial comments

Shivani

2021-09-01 15:03:56

Learning a lot from the courses present on atutorialhub. The courses are very well explained. Great experience

html tutorial comments

Harshitha

2021-09-10 15:05:45

It is very helpful to students and easy to learn the concepts

html tutorial comments

Sowmya

2021-09-14 15:06:41

Great job Tutorials are easy to understand Please make use of it

html tutorial comments

Zain Khan

2021-09-18 15:07:23

Great content and customized courses.

html tutorial comments

Rudrakshi Bhatt

2021-09-09 15:08:10

Well structured coursed and explained really well!

html tutorial comments

Pavana Somashekar

2021-09-11 15:09:08

Good platform for beginners and learn a lot on this website