explain.depesz.com

PostgreSQL's explain analyze made readable

Result: lZ6

Settings
# exclusive inclusive rows x rows loops node
1. 0.031 1,108.353 ↑ 1.0 45 1

Limit (cost=360,064.48..360,064.60 rows=45 width=306) (actual time=1,108.316..1,108.353 rows=45 loops=1)

2. 41.179 1,108.322 ↑ 1,184.0 45 1

Sort (cost=360,064.48..360,197.68 rows=53,279 width=306) (actual time=1,108.314..1,108.322 rows=45 loops=1)

  • Sort Key: person_smart_attributes.last_event_date DESC NULLS LAST, companies.id
  • Sort Method: top-N heapsort Memory: 37kB
3. 49.142 1,067.143 ↓ 1.7 89,515 1

Merge Left Join (cost=33,603.97..358,335.09 rows=53,279 width=306) (actual time=53.129..1,067.143 rows=89,515 loops=1)

  • Merge Cond: (companies.id = companies_persons.company_id)
4. 115.725 957.731 ↓ 1.7 89,515 1

Nested Loop (cost=0.86..324,596.50 rows=53,279 width=274) (actual time=0.062..957.731 rows=89,515 loops=1)

5. 35.651 35.651 ↑ 1.0 89,595 1

Index Only Scan using organizations_relevant_companies_organization_id_company_id_idx on organizations_relevant_companies (cost=0.43..14,635.36 rows=92,746 width=4) (actual time=0.038..35.651 rows=89,595 loops=1)

  • Index Cond: (organization_id = 7)
  • Heap Fetches: 89595
6. 806.355 806.355 ↑ 1.0 1 89,595

Index Scan using companies_pkey on companies (cost=0.43..3.33 rows=1 width=274) (actual time=0.009..0.009 rows=1 loops=89,595)

  • Index Cond: (id = organizations_relevant_companies.company_id)
  • Filter: (((organization_id = 7) OR (organization_id IS NULL)) AND (id <> ALL ('{161800872,162557504,58730420,148821180,164006542,1590904,136380421,161850747,161878208,197473816,1780258,164006542,1630399,158344254,1553029,1733171,161818105,149474826,2167322,1514731,148821510,1536609,1527003,1666699,163278493,161870196,1630706,1584523,198234314,113832612,1586770,1706391,163315430,163320504,163320765,163322842,164746678,164737072,164733520,164733961,164734115,164734309,164735094,164735804,164746655,164741776,164742878,164743145,164747090,164755083,164755145,164755541,164755822,164748615,164748490,139436107,164748603,164749651,164750361,179179719,164751166,164752049,164753417,179591941,164757631,164757977,164757888,181632373,177965294,198223188,198224316,198224855,198226126,198229055,198227264,198229129,198228191,198230160,198231459,198233382,198233399,198234591,202533098,100247194,198237641,198247484,115156478,136320326,1806478,138205468,198242396,198247374,198242816,198243714,1785453,198246656,198248892,198249581,201780906,201781137,201781716,201781707,201783550,201784247,1585147,201794464,201794467,201794510,201795343,201795557,201795489,201797787,157664549,201803057,201805258,201805516,201812020,79713712,136324658,157665385,1667614,32735905,116047692,1760595,200341889,147495709,136371828,1794131,201808357,201825951,148157949,1660241,162556406,149474711,1723668,1578758,159035387,201809882,201826124,201810616,201810428,136374187,15941760,136386511,201810828,201826443,136352272,201817530,1636043,197470362,23896956,2177561,1805361,1526673,150129846,1816654,1521927,136378359,32735731,1572766,1723376,136331222,73101444,160423737,136306527,136305978,136317178,1554208,136302354,1815000,148819953,136382832,141754210,136334302,151466576,136303917,116945339,137592338,136301411,127864864,143639337,156979659,141755244,157667126,136354991,1555903,1539960,143638263,136385827,140047509,1637180,122027499,1701562,157664580,1749036,140045838,157665403,136373155,1536036,136374314,148820671,1635673,1546767,136335673,1796456,148158123,136354876,136305402,2184457,132105520,138820356,1575045,1670084,113830985,1797496,1554157,2159279,140046469,1710093,1766864,136301137,136345445,78829480,131082165,142372818,142374005,136319834,164719902,136325866,136334267,136989562,1627272,136350830,1799773,163278087,136379112,136363025,136322667,136331822,136310680,126382328,136352045,136361676,1613667,136323174,2540618,1534626,136302510,136387538,136359272,1795596,1527941,198217342,150127676,136340631,1524310,136366982,136341033,1808715,136352342,1596593,124901747,136316401,152823364,1567305,121554210,144905218,1638412,162556259,137591818,56837525,146196734,163278271,163278276,74998500,120608921,1661672,140047024,1654654,136383897,136362467,1655108,136363843,1763112,136323951,136368143,136317724,136307606,136322019,136354982,1757443,136382926,163278361,136344760,136380306,148154694,1525924,136349969,136338568,136375580,136372374,2539743,1725210,78854802,136363710,136335320,1654273,136989330,1577361,1703153,136363380,198217421,136303759,136346575,198217423,158344784,136347108,136322964,153517007,132105464,78833541,1790813,148155835,144907823,118761440,1798716,1600508,136366309,163278502,148818480,150795784,136326797,137589240,145558604,136340003,136375258,160424243,1803102,141754662,152148243,136383216,1708970,1544388,126876946,78831212,136338684,136345376,136325015,160424658,136315405,2162454,136334198,136355582,1774164,122979742,197470327,128865547,1653719,118306416,200339301,143637341,136334833,136364216,136353944,1636192,37582437,1710367,124902910,1585979,1772094,29774482,200339066,164720149,136318203,1587315,1732111,136356171,1577627,163278785,136324051,1598215,1708583,136312060,136366994,161107983,160425891,136332273,136359536,116944441,136373050,164720189,136312738,136350114,136320119,136345900,136350138,1691438,78836420,157664332,74998663,1524571,136347892,200340391,159036523,148155428,121079667,148158538,1746192,1599645,1786393,136387076,2160687,164720223,120609151,136320431,1555842,150131023,1701028,1515040,154213483,161108349,136319334,112951688,136335773,147494214,136356926,136362629,1812674,136331412,163279076,1700795,2164992,1730765,136324301,1779996,136327236,136316606,122504503,1530271,136323105,136374444,1551865,138205487,136354351,136366275,1516074,154903012,136310844,158343740,128363468,136311584,124904181,153516324,1763605,1748681,136311991,197470507,147495102,1580849,1603519,136323512,2185911,136313936,120610956,136382543,161108139,112951778,154900153,1701958,1628029,1734061,136356272,139435660,143639391,143637709,1795739,164720310,198217662,138204937,146198689,159035484,136302757,136357364,1694878,149474464,136338624,2539254,136311979,1650843,141752599,136380857,144271768,78844509,93392570,147494456,81425899,136356399,136303647,112511693,1631543,1719754,1633002,136340412,136326190,78838072,114714004,136325316,163279418,150130399,1611056,161799896,136314210,148158278,136347680,163279442,136370627,136321052,148156772,152820594,114273034,136334931,136384286,136353550,136352186,142373079,136375392,136352373,136353366,159037964,136353428,136381195,1648397,1763409,1665083,136314117,1805382,136337063,160422933,136363694,136372950,136323472,136311535,78832986,160424599,150128586,2537363,138205472,120608755,1779172,164005744,136352097,136355922,1622227,1592721,1728851,136344442,1548325,146842737,137593249,136987316,143637877,136345184,1733990,1618274,155612379,1691065,136311511,79709329,124897776,136314238,1686213,161109277,1537511,136367373,124900744,136319527,136367230,136308460,60618928,151466723,120600684,136361122,2162973,136364727,2165241,136321229,198217827,136371331,1722021,121080971,136318548,136374145,1690674,138207338,161107229,1531342,144272574,152820489,111195246,163279933,1616636,160425359,1775769,136354370,136339039,136323602,144908244,136310762,136365880,136349908,1520005,136331856,136341869,136362201,1532675,1596575,1546618,15583749,136381160,136375000,157664026,143637959,115602433,136314986,146199441,1575756,136302123,163280105,136356746,150794361,136346119,136344584,144270304,136361170,136320383,1688910,136332947,136334891,136351179,1592303,136353573,136352281,143638280,1585626,159035625,2532925,136342869,1590985,136371689,136384720,136305928,136371120,136320971,1727313,201777379,140659066,120602616,1556310,136362662,159740521,32736828,1789757,1692255,136302212,2179101,136373472,112953479,136354310,163280318,78837459,1662361,116944935,1562723,136360290,139434920,2179615,3236005,164005950,79708815,136350628,136319538,1750912,136363218,1577519,198217967,1586858,159037394,148155760,146844984,1709478,1522323,136313995,1735896,136344323,163280403,120611066,118306048,78862366,136319615,163280445,148155620,1633131,136339487,1624235,115602402,136300867,163280494,136987084,154212516,1662701,1794262,2185848,160425533,2161966,141752555,117847377,136374586,136370739,136355695,6048650,118306912,136306907,136312184,128864951,146844686,1725588,110153420,1577787,148153980,1616065,136330851,136339742,136363723,41332219,136329400,1569889,136336127,136344395,136378020,119672611,163280643,136347618,40577577,136311575,44355752,1751727,1625525,136347837,154212491,163280674,1536268,143003466,1663088,143640756,136340486,136353245,155613087,137592131,113833022,136350497,1747283,148820431,136377475,136302139,153515705,136333528,159738372,136342449,136317780,156297531,136317105,14871546,136306056,159738211,150127806,163280747,150129462,136350276,1799047,158345891,2171806,1538138,136359051,136354704,136374432,136351768,136383600,2171774,1520656,136344234,1521203,136376441,1739851,129730555,136346539,1567713,136322757,1814304,146198609,95532936,136355718,136336216,163280854,1557095,136355632,1790381,136329143,153518290,125885754,136342104,201777539,136364999,136383178,1748251,2164304,136328146,136385094,136355548,74999242,136332470,136332669,136324256,136350940,1754259,121553889,144906421,1730391,1525563,1600443,136331657,1646065,136344609,136388066,144905514,136354902,136310836,152147088,139436238,136370845,146200890,1688971,136336406,1617432,1541502,148153933,136368228,136375998,136312636,151466861,136317180,1745724,156297628,147498390,136364099,1526381,153519006,155615902,1794844,1821912,143006965,79711506,146842952,1801066,78833256,143641128,136386973,133414062,1531150,136338177,136336173,136301302,136366882,144906222,160422752,136350510,136382913,136352274,1658500,138205728,1520949,126384005,78858124,141755272,126383153,136350983,1741720,141752641,1735011,156977803,1683119,129730197,136364545,136326720,1615976,156297134,136340956,120608956,163281257,124905005,136387645,156295933,1654893,123929686,1734157,78830066,1562474,159037241,136360809,136354197,136372271,136352346,200339618,136368806,136325115,136306329,79706364,136322823,136310211,2163108,1589664,1718977,1813836,136311398,136355915,1709165,2537632,74997921,1713934,1532688,154211301,142374127,1711418,136372413,1772863,154906967,1819494,136364664,1548962,1519722,136371770,1707166,1568487,136301099,136343910,136353165,136355699,197471295,156978727,136301323,27927079,1575316,140045890,139436081,136305985,1739493,161109248,1627618,1690059,1577970,78842160,151469214,1799054,136384200,150794892,1813454,1747810,1757321,1728086,136359338,144908187,136335843,143641058,1593341,78841466,163281591,136380755,111635034,33109624,136330518,124901640,2175188,136379843,145561252,74997581,122978115,144907892,159037291,136385197,39078629,201777734,156979244,151467515,1652300,136317484,78842669,1645431,136366251,1738477,136370182,133414452,1649737,1723563,136376842,163281713,163281714,78836953,1681464,157663350,1648170,136341668,136388076,1660521,141755129,2540163,136306620,150795474,1527602,2178357,136352852,158344552,136386660,122977335,136356164,136375335,136370009,147495667,136371958,136334394,1701226,159036774,136339542,152822215}'::integer[])))
  • Rows Removed by Filter: 0
7. 1.641 60.270 ↓ 32.4 3,626 1

Materialize (cost=33,603.11..33,605.07 rows=112 width=16) (actual time=53.062..60.270 rows=3,626 loops=1)

8. 2.820 58.629 ↓ 32.4 3,626 1

Unique (cost=33,603.11..33,603.67 rows=112 width=16) (actual time=53.058..58.629 rows=3,626 loops=1)

9. 6.776 55.809 ↓ 69.9 7,831 1

Sort (cost=33,603.11..33,603.39 rows=112 width=16) (actual time=53.057..55.809 rows=7,831 loops=1)

  • Sort Key: companies_persons.company_id, person_smart_attributes.last_event_date DESC NULLS LAST
  • Sort Method: quicksort Memory: 560kB
10. 4.423 49.033 ↓ 69.9 7,831 1

Nested Loop (cost=0.73..33,599.30 rows=112 width=16) (actual time=0.028..49.033 rows=7,831 loops=1)

11. 3.235 3.235 ↓ 1.0 8,275 1

Index Scan using person_smart_attributes_temp_organization_id_person_id_idx on person_smart_attributes (cost=0.29..676.54 rows=8,221 width=16) (actual time=0.016..3.235 rows=8,275 loops=1)

  • Index Cond: (organization_id = 7)
12. 41.375 41.375 ↑ 1.0 1 8,275

Index Scan using companies_persons_person_id_index on companies_persons (cost=0.43..3.99 rows=1 width=8) (actual time=0.004..0.005 rows=1 loops=8,275)

  • Index Cond: (person_id = person_smart_attributes.person_id)
  • Filter: (organization_id = 7)