EXPLAIN, optimizer ఎంచుకున్న plan ను చూపిస్తుంది — అది ప్రతి table ను ఎలా access చేస్తుందో — query ను run చేయకుండా. indexes ఉపయోగించబడుతున్నాయని మరియు కొన్ని rows మాత్రమే పరిశీలించబడుతున్నాయని నిర్ధారించడానికి మీరు దాన్ని చదువుతారు.
EXPLAIN, optimizer ఎంచుకున్న plan ను చూపిస్తుంది — అది ప్రతి table ను ఎలా access చేస్తుందో — query ను run చేయకుండా. indexes ఉపయోగించబడుతున్నాయని మరియు కొన్ని rows మాత్రమే పరిశీలించబడుతున్నాయని నిర్ధారించడానికి మీరు దాన్ని చదువుతారు.
const / eq_ref / ref (index lookups, మంచిది) → range → index (full index scan) → ALL (full table scan, హెచ్చరిక సంకేతం).NULL = ఏదీ కాదు).Using index (covering, గొప్పది), Using filesort / Using temporary (memory లో లేదా disk పై sorting/grouping — తరచుగా optimize చేయదగినది).EXPLAIN SELECT * FROM orders WHERE customer_id = 42 ORDER BY created_at;
-- +------+------+------+---------+--------+----------------+
-- | type | key | rows | Extra |
-- | ALL | NULL | 900k | Using where; Using filesort | <- scans everything, sorts
-- +------+------+------+---------+--------+----------------+
-- Add an index that covers the filter AND the sort order:
CREATE INDEX idx_cust_created ON orders (customer_id, created_at);
EXPLAIN SELECT * FROM orders WHERE customer_id = 42 ORDER BY created_at;
-- | type | key | rows | Extra |
-- | ref | idx_cust_created | 30 | Using where | <- seeks 30 rows, no filesort
index, 900k rows యొక్క ALL scan ను 30 యొక్క ref seek గా మార్చింది, మరియు created_at రెండవ column కావడం వల్ల, rows ముందుగానే sort అయి వస్తాయి — filesort అదృశ్యమవుతుంది.
నిజమైన timing మరియు row counts ను కూడా చూడటానికి EXPLAIN ANALYZE (MySQL 8) ను ఉపయోగించండి, అంచనా తప్పుగా ఉన్న సందర్భాలను పట్టుకోవడానికి.
ఊహలను evidence తో భర్తీ చేసే మార్గం EXPLAIN. type: ALL, భారీ rows, లేదా Using filesort ను గుర్తించడం, index ఎక్కడ లేదో ఖచ్చితంగా చెబుతుంది — "page నెమ్మదిగా ఉంది" నుండి ఒక targeted fix కు అత్యంత వేగవంతమైన మార్గం.
జూనియర్ నుండి సీనియర్ వరకు వివరణాత్మక సమాధానాలతో IT ఇంటర్వ్యూ ప్రశ్నల లైబ్రరీ.
విరాళం