相关文章推荐
小百科
›
统计信息简介 | PingCAP 文档中心
table
tidb
mysql创建索引
mysql update语句
拉风的电池
8 月前
</noscript><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-TPX49SBK" height="0" width="0" style="display: none; visibility: hidden" aria-hidden="true"/></noscript><div id="___gatsby"><div style="outline:none" tabindex="-1" id="gatsby-focus-wrapper"><style data-emotion="css 6ko3zs">.css-6ko3zs{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;width:100%;box-sizing:border-box;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;position:fixed;z-index:1100;top:0;left:auto;right:0;background-color:#1976d2;color:#fff;background-color:#f9f9f9;border-bottom:1px solid #e5e5e5;box-shadow:0px 1px 6px rgba(0, 0, 0, 0.08);height:5rem;}@media print{.css-6ko3zs{}}</style><style data-emotion="css foju0o">.css-foju0o{background-color:#fff;color:rgba(0, 0, 0, 0.87);-webkit-transition:box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;box-shadow:0px 2px 4px -1px rgba(0,0,0,0.2),0px 4px 5px 0px rgba(0,0,0,0.14),0px 1px 10px 0px rgba(0,0,0,0.12);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;width:100%;box-sizing:border-box;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;position:fixed;z-index:1100;top:0;left:auto;right:0;background-color:#1976d2;color:#fff;background-color:#f9f9f9;border-bottom:1px solid #e5e5e5;box-shadow:0px 1px 6px rgba(0, 0, 0, 0.08);height:5rem;}@media print{.css-foju0o{}}</style><header class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation4 MuiAppBar-root MuiAppBar-colorPrimary MuiAppBar-positionFixed doc-site-header mui-fixed css-foju0o"><style data-emotion="css 1xw2ef0">.css-1xw2ef0{position:relative;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;padding-left:16px;padding-right:16px;min-height:56px;height:100%;}@media (min-width:600px){.css-1xw2ef0{padding-left:24px;padding-right:24px;}}@media (min-width:0px){@media (orientation: landscape){.css-1xw2ef0{min-height:48px;}}}@media (min-width:600px){.css-1xw2ef0{min-height:64px;}}@media (min-width:900px){.css-1xw2ef0{padding-left:2rem;padding-right:2rem;}}</style><div class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular css-1xw2ef0"><style data-emotion="css 16bbyrv">.css-16bbyrv{text-align:center;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;font-size:1.5rem;padding:8px;border-radius:50%;overflow:visible;color:rgba(0, 0, 0, 0.54);-webkit-transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;}.css-16bbyrv:hover{background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-16bbyrv:hover{background-color:transparent;}}.css-16bbyrv.Mui-disabled{background-color:transparent;color:rgba(0, 0, 0, 0.26);}@media (min-width:1200px){.css-16bbyrv{;}}</style><style data-emotion="css iuftj9">.css-iuftj9{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;position:relative;box-sizing:border-box;-webkit-tap-highlight-color:transparent;background-color:transparent;outline:0;border:0;margin:0;border-radius:0;padding:0;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;-moz-appearance:none;-webkit-appearance:none;-webkit-text-decoration:none;text-decoration:none;color:inherit;text-align:center;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;font-size:1.5rem;padding:8px;border-radius:50%;overflow:visible;color:rgba(0, 0, 0, 0.54);-webkit-transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;}.css-iuftj9::-moz-focus-inner{border-style:none;}.css-iuftj9.Mui-disabled{pointer-events:none;cursor:default;}@media print{.css-iuftj9{-webkit-print-color-adjust:exact;color-adjust:exact;}}.css-iuftj9:hover{background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-iuftj9:hover{background-color:transparent;}}.css-iuftj9.Mui-disabled{background-color:transparent;color:rgba(0, 0, 0, 0.26);}@media (min-width:1200px){.css-iuftj9{;}}</style><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-iuftj9" tabindex="0" type="button" aria-label="menu"><style data-emotion="css vubbuv">.css-vubbuv{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:1em;height:1em;display:inline-block;fill:currentColor;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;font-size:1.5rem;}</style><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-vubbuv" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="MenuIcon"><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/></svg></button><style data-emotion="css a3xyjy">.css-a3xyjy{z-index:1200;}</style><style data-emotion="css 13tqxrv">@media (min-width:0px){.css-13tqxrv{;}}@media (min-width:900px){.css-13tqxrv{display:block;}}</style><div class="MuiBox-root css-13tqxrv"><style data-emotion="css tx8jsd">.css-tx8jsd{margin:0;font-size:1rem;line-height:1.5rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:#666666;}</style><a class="MuiTypography-root MuiTypography-body1 css-tx8jsd" target="_blank" href="https://cn.pingcap.com/" style="text-decoration:none"><style data-emotion="css uz5bjn">.css-uz5bjn{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:1em;height:1em;display:inline-block;fill:currentColor;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;font-size:1.5rem;width:6.75rem;}@media (min-width:0px){.css-uz5bjn{;}}@media (min-width:600px){.css-uz5bjn{display:block;}}</style><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-uz5bjn" focusable="false" aria-hidden="true" viewbox="0 0 769.89 203.08"><g id="Layer_2" data-name="Layer 2"><g id="Layer_1-2" data-name="Layer 1"><path fill="#082265" d="M100.11,47.34l-88-25.1A9.5,9.5,0,0,0,0,31.38v162.2a9.51,9.51,0,0,0,9.48,9.5,9.35,9.35,0,0,0,2.22-.26l88-21h0a9.48,9.48,0,0,0,7.3-9.25V56.48A9.54,9.54,0,0,0,100.11,47.34Z"/><path fill="#00aeef" d="M160.05,41.57a9.55,9.55,0,0,0-6.88-9.11L41.16.37A9.5,9.5,0,0,0,29,9.51V132.59a9.47,9.47,0,0,0,11.72,9.23l112.14-27a9.47,9.47,0,0,0,7.28-9.26Z"/><path fill="#303eab" d="M100.11,47.34,29,27.07V132.59a9.47,9.47,0,0,0,11.72,9.23L107,125.88V56.48A9.54,9.54,0,0,0,100.11,47.34Z"/><path fill="#082265" d="M576.1,126.26h0l-.23.37a40.12,40.12,0,0,1-13.72,13.09,36.62,36.62,0,0,1-18.78,5.43c-10.94,0-20.51-4.36-28.42-13a43.82,43.82,0,0,1-11.37-31,43.09,43.09,0,0,1,11.74-29.38c7.62-8.17,16.81-12.31,27.3-12.31,14.37-.13,25.2,5.8,33.13,18.13L576,78h.22l9.33-5.77a51.65,51.65,0,0,0-15.42-16.39,48.17,48.17,0,0,0-26.73-8.09A46.85,46.85,0,0,0,507.66,63c-9.94,10.23-15,23.28-15,38.77,0,15,5,28.08,14.84,38.9,9.81,10.64,21.69,16,35.33,16h.51c17.92-.37,32.69-9.06,42.11-24.6Z"/><polygon fill="#082265" points="645.84 49.09 633.16 49.09 586.01 154.63 601.05 154.63 615.63 119.55 615.65 119.55 620.8 108.59 620.78 108.59 639.76 64.05 658.36 108.59 631.66 108.59 626.79 119.55 662.69 119.55 677.4 154.63 690.66 154.63 645.84 49.09"/><path fill="#082265" d="M759.63,58.75c-7-6.32-15.81-9.52-26.18-9.52H699.3v105.4h12.44V113.34h0V102.25h0V60.59H734a24.73,24.73,0,0,1,16.22,5.63,18.12,18.12,0,0,1,7.37,14c.39,6.62-1.77,11.88-6.61,16.07a23.43,23.43,0,0,1-16.31,6H721.77v11.09h14.91a33.34,33.34,0,0,0,23.23-8.85,29,29,0,0,0,10-21.91C770,72.89,766.58,64.87,759.63,58.75Z"/><rect fill="#082265" x="296.25" y="51.17" width="12.44" height="12.44"/><rect fill="#082265" x="296.25" y="79.04" width="12.44" height="75.74"/><path fill="#082265" d="M483.63,147.21V114.69a38.6,38.6,0,0,0-12.25-29.2c-8.22-8.22-18.1-12.27-29.35-12a39.17,39.17,0,0,0-27.82,12.54,40.08,40.08,0,0,0-11.29,28.49,41,41,0,0,0,12.24,29.59c8.19,8.18,18,12.12,29.22,11.71a38.78,38.78,0,0,0,27.48-12.33v5.17m0,0c0,6.88-2.73,12.89-8.11,17.88a27.1,27.1,0,0,1-19,7.73,27.83,27.83,0,0,1-16.93-5.64,25.92,25.92,0,0,1-9-10.54l-9.52,5.5a36.63,36.63,0,0,0,9.94,12c6.6,5.25,14.75,8.13,24.23,8.54.59,0,1.18,0,1.77,0a40.89,40.89,0,0,0,26-9.25c8.17-6.52,12.32-14.86,12.32-24.8v-2.95m-12-31.74a29.23,29.23,0,0,1-8.41,20.22,25.68,25.68,0,0,1-19.5,8.38,27.3,27.3,0,0,1-20.2-8.39,28.22,28.22,0,0,1-8.66-20.34,28.66,28.66,0,0,1,7.88-20.61,27.21,27.21,0,0,1,19.53-9.45c.51,0,1,0,1.5,0,7.61,0,14,2.85,19.45,8.69A28.51,28.51,0,0,1,471.59,115.47Z"/><path fill="#082265" d="M274.1,58.75c-7-6.32-15.81-9.52-26.19-9.52H213.76v105.4h12.45V113.34h0V102.25h0V60.59h22.24a24.73,24.73,0,0,1,16.23,5.63,18.12,18.12,0,0,1,7.37,14c.39,6.62-1.77,11.88-6.61,16.07a23.43,23.43,0,0,1-16.31,6H236.24v11.09h14.91a33.34,33.34,0,0,0,23.23-8.85,29,29,0,0,0,10-21.91C284.5,72.89,281.05,64.87,274.1,58.75Z"/><path fill="#082265" d="M357.54,74.41c-9.92,0-18.3,3.43-24.94,10.2s-9.91,15.24-9.91,25.33v44.53h12V108.86a21.82,21.82,0,0,1,6.75-16.1A22.08,22.08,0,0,1,357.54,86a21.49,21.49,0,0,1,15.82,6.75,21.86,21.86,0,0,1,6.89,16.1v45.61h12V109.94c0-10.09-3.34-18.61-9.92-25.33A33.47,33.47,0,0,0,357.54,74.41Z"/></g></g></svg></a></div><style data-emotion="css 5qlh60">.css-5qlh60{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;padding-left:2rem;height:100%;}.css-5qlh60>:not(style)+:not(style){margin:0;margin-left:24px;}@media (min-width:0px){.css-5qlh60{;}}@media (min-width:900px){.css-5qlh60{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}}</style><div class="css-5qlh60"><style data-emotion="css kiou0g">.css-kiou0g{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;padding-top:0.25rem;padding-bottom:0.25rem;}</style><div class="MuiBox-root css-kiou0g"><a style="text-decoration:none" hreflang="zh" href="/zh/"><style data-emotion="css 2jgwiy">.css-2jgwiy{margin:0;font-size:1rem;line-height:1.5rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:#666666;color:#282a36;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,"IBM Plex Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji";display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:4px;}</style><div class="MuiTypography-root MuiTypography-body1 css-2jgwiy">文档中心</div></a></div><div class="MuiBox-root css-kiou0g"><a style="text-decoration:none" hreflang="zh" href="/zh/tidb/stable"><div class="MuiTypography-root MuiTypography-body1 css-2jgwiy">TiDB</div></a></div><div class="MuiBox-root css-kiou0g"><a class="MuiTypography-root MuiTypography-body1 css-tx8jsd" target="_blank" href="https://asktug.com/" style="text-decoration:none"><div class="MuiTypography-root MuiTypography-body1 css-2jgwiy">社区</div></a></div><div class="MuiBox-root css-kiou0g"><a class="MuiTypography-root MuiTypography-body1 css-tx8jsd" target="_blank" href="https://cn.pingcap.com/contact/" style="text-decoration:none"><div class="MuiTypography-root MuiTypography-body1 css-2jgwiy">联系我们</div></a></div><div class="MuiBox-root css-kiou0g"><a class="MuiTypography-root MuiTypography-body1 css-tx8jsd" target="_blank" href="https://cn.pingcap.com/product/#SelectProduct" style="text-decoration:none"><div class="MuiTypography-root MuiTypography-body1 css-2jgwiy"><style data-emotion="css xnd31y">.css-xnd31y{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:1em;height:1em;display:inline-block;fill:currentColor;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;font-size:inherit;padding-top:0.5rem;}</style><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-xnd31y" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="DownloadIcon"><path d="M5 20h14v-2H5v2zM19 9h-4V3H9v6H5l7 7 7-7z"/></svg></div></a></div></div><style data-emotion="css 1vn3uc0">.css-1vn3uc0{color:#282a36;}@media (min-width:900px){.css-1vn3uc0{;}}</style><div class="MuiBox-root css-1vn3uc0"><style data-emotion="css btg76o">.css-btg76o{text-transform:none;font-family:-apple-system,"Poppins","Helvetica Neue",sans-serif,"Noto Sans","Fira Code","IBM Plex Sans","sans-serif";font-weight:500;font-size:0.875rem;line-height:1.75;min-width:64px;padding:6px 8px;border-radius:4px;-webkit-transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;color:inherit;border-color:currentColor;box-shadow:none;}.css-btg76o:hover{-webkit-text-decoration:none;text-decoration:none;background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-btg76o:hover{background-color:transparent;}}.css-btg76o.Mui-disabled{color:rgba(0, 0, 0, 0.26);}.css-btg76o:hover{box-shadow:none;}.css-btg76o.Mui-focusVisible{box-shadow:none;}.css-btg76o:active{box-shadow:none;}.css-btg76o.Mui-disabled{box-shadow:none;}</style><style data-emotion="css 1ei260h">.css-1ei260h{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;position:relative;box-sizing:border-box;-webkit-tap-highlight-color:transparent;background-color:transparent;outline:0;border:0;margin:0;border-radius:0;padding:0;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;-moz-appearance:none;-webkit-appearance:none;-webkit-text-decoration:none;text-decoration:none;color:inherit;text-transform:none;font-family:-apple-system,"Poppins","Helvetica Neue",sans-serif,"Noto Sans","Fira Code","IBM Plex Sans","sans-serif";font-weight:500;font-size:0.875rem;line-height:1.75;min-width:64px;padding:6px 8px;border-radius:4px;-webkit-transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;color:inherit;border-color:currentColor;box-shadow:none;}.css-1ei260h::-moz-focus-inner{border-style:none;}.css-1ei260h.Mui-disabled{pointer-events:none;cursor:default;}@media print{.css-1ei260h{-webkit-print-color-adjust:exact;color-adjust:exact;}}.css-1ei260h:hover{-webkit-text-decoration:none;text-decoration:none;background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-1ei260h:hover{background-color:transparent;}}.css-1ei260h.Mui-disabled{color:rgba(0, 0, 0, 0.26);}.css-1ei260h:hover{box-shadow:none;}.css-1ei260h.Mui-focusVisible{box-shadow:none;}.css-1ei260h:active{box-shadow:none;}.css-1ei260h.Mui-disabled{box-shadow:none;}</style><button class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textInherit MuiButton-sizeMedium MuiButton-textSizeMedium MuiButton-colorInherit MuiButton-disableElevation css-1ei260h" tabindex="0" type="button" id="header-nav-items" aria-haspopup="true"><style data-emotion="css 6xugel">.css-6xugel{display:inherit;margin-right:8px;margin-left:-4px;}.css-6xugel>*:nth-of-type(1){font-size:20px;}</style><span class="MuiButton-startIcon MuiButton-iconSizeMedium css-6xugel"><style data-emotion="css 1x9zct">.css-1x9zct{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:1em;height:1em;display:inline-block;fill:currentColor;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;font-size:1.5rem;width:6.75rem;height:1.5rem;}</style><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1x9zct" focusable="false" aria-hidden="true" viewbox="0 0 769.89 203.08"><g id="Layer_2" data-name="Layer 2"><g id="Layer_1-2" data-name="Layer 1"><path fill="#082265" d="M100.11,47.34l-88-25.1A9.5,9.5,0,0,0,0,31.38v162.2a9.51,9.51,0,0,0,9.48,9.5,9.35,9.35,0,0,0,2.22-.26l88-21h0a9.48,9.48,0,0,0,7.3-9.25V56.48A9.54,9.54,0,0,0,100.11,47.34Z"/><path fill="#00aeef" d="M160.05,41.57a9.55,9.55,0,0,0-6.88-9.11L41.16.37A9.5,9.5,0,0,0,29,9.51V132.59a9.47,9.47,0,0,0,11.72,9.23l112.14-27a9.47,9.47,0,0,0,7.28-9.26Z"/><path fill="#303eab" d="M100.11,47.34,29,27.07V132.59a9.47,9.47,0,0,0,11.72,9.23L107,125.88V56.48A9.54,9.54,0,0,0,100.11,47.34Z"/><path fill="#082265" d="M576.1,126.26h0l-.23.37a40.12,40.12,0,0,1-13.72,13.09,36.62,36.62,0,0,1-18.78,5.43c-10.94,0-20.51-4.36-28.42-13a43.82,43.82,0,0,1-11.37-31,43.09,43.09,0,0,1,11.74-29.38c7.62-8.17,16.81-12.31,27.3-12.31,14.37-.13,25.2,5.8,33.13,18.13L576,78h.22l9.33-5.77a51.65,51.65,0,0,0-15.42-16.39,48.17,48.17,0,0,0-26.73-8.09A46.85,46.85,0,0,0,507.66,63c-9.94,10.23-15,23.28-15,38.77,0,15,5,28.08,14.84,38.9,9.81,10.64,21.69,16,35.33,16h.51c17.92-.37,32.69-9.06,42.11-24.6Z"/><polygon fill="#082265" points="645.84 49.09 633.16 49.09 586.01 154.63 601.05 154.63 615.63 119.55 615.65 119.55 620.8 108.59 620.78 108.59 639.76 64.05 658.36 108.59 631.66 108.59 626.79 119.55 662.69 119.55 677.4 154.63 690.66 154.63 645.84 49.09"/><path fill="#082265" d="M759.63,58.75c-7-6.32-15.81-9.52-26.18-9.52H699.3v105.4h12.44V113.34h0V102.25h0V60.59H734a24.73,24.73,0,0,1,16.22,5.63,18.12,18.12,0,0,1,7.37,14c.39,6.62-1.77,11.88-6.61,16.07a23.43,23.43,0,0,1-16.31,6H721.77v11.09h14.91a33.34,33.34,0,0,0,23.23-8.85,29,29,0,0,0,10-21.91C770,72.89,766.58,64.87,759.63,58.75Z"/><rect fill="#082265" x="296.25" y="51.17" width="12.44" height="12.44"/><rect fill="#082265" x="296.25" y="79.04" width="12.44" height="75.74"/><path fill="#082265" d="M483.63,147.21V114.69a38.6,38.6,0,0,0-12.25-29.2c-8.22-8.22-18.1-12.27-29.35-12a39.17,39.17,0,0,0-27.82,12.54,40.08,40.08,0,0,0-11.29,28.49,41,41,0,0,0,12.24,29.59c8.19,8.18,18,12.12,29.22,11.71a38.78,38.78,0,0,0,27.48-12.33v5.17m0,0c0,6.88-2.73,12.89-8.11,17.88a27.1,27.1,0,0,1-19,7.73,27.83,27.83,0,0,1-16.93-5.64,25.92,25.92,0,0,1-9-10.54l-9.52,5.5a36.63,36.63,0,0,0,9.94,12c6.6,5.25,14.75,8.13,24.23,8.54.59,0,1.18,0,1.77,0a40.89,40.89,0,0,0,26-9.25c8.17-6.52,12.32-14.86,12.32-24.8v-2.95m-12-31.74a29.23,29.23,0,0,1-8.41,20.22,25.68,25.68,0,0,1-19.5,8.38,27.3,27.3,0,0,1-20.2-8.39,28.22,28.22,0,0,1-8.66-20.34,28.66,28.66,0,0,1,7.88-20.61,27.21,27.21,0,0,1,19.53-9.45c.51,0,1,0,1.5,0,7.61,0,14,2.85,19.45,8.69A28.51,28.51,0,0,1,471.59,115.47Z"/><path fill="#082265" d="M274.1,58.75c-7-6.32-15.81-9.52-26.19-9.52H213.76v105.4h12.45V113.34h0V102.25h0V60.59h22.24a24.73,24.73,0,0,1,16.23,5.63,18.12,18.12,0,0,1,7.37,14c.39,6.62-1.77,11.88-6.61,16.07a23.43,23.43,0,0,1-16.31,6H236.24v11.09h14.91a33.34,33.34,0,0,0,23.23-8.85,29,29,0,0,0,10-21.91C284.5,72.89,281.05,64.87,274.1,58.75Z"/><path fill="#082265" d="M357.54,74.41c-9.92,0-18.3,3.43-24.94,10.2s-9.91,15.24-9.91,25.33v44.53h12V108.86a21.82,21.82,0,0,1,6.75-16.1A22.08,22.08,0,0,1,357.54,86a21.49,21.49,0,0,1,15.82,6.75,21.86,21.86,0,0,1,6.89,16.1v45.61h12V109.94c0-10.09-3.34-18.61-9.92-25.33A33.47,33.47,0,0,0,357.54,74.41Z"/></g></g></svg></span><style data-emotion="css 1n4a93h">.css-1n4a93h{display:inherit;margin-right:-4px;margin-left:8px;}.css-1n4a93h>*:nth-of-type(1){font-size:20px;}</style><span class="MuiButton-endIcon MuiButton-iconSizeMedium css-1n4a93h"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-vubbuv" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="KeyboardArrowDownIcon"><path d="M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z"/></svg></span></button></div><style data-emotion="css jnv64h">.css-jnv64h{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;margin-left:auto;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}@media (min-width:0px){.css-jnv64h>:not(style)+:not(style){margin:0;margin-left:8px;}}@media (min-width:1200px){.css-jnv64h>:not(style)+:not(style){margin:0;margin-left:24px;}}</style><div class="css-jnv64h"><style data-emotion="css 1qlh2t1">.css-1qlh2t1{color:#282a36;}</style><div class="MuiBox-root css-1qlh2t1"><style data-emotion="css 1mvsusm">.css-1mvsusm{text-align:center;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;font-size:1.5rem;padding:8px;border-radius:50%;overflow:visible;color:rgba(0, 0, 0, 0.54);-webkit-transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;color:inherit;}.css-1mvsusm:hover{background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-1mvsusm:hover{background-color:transparent;}}.css-1mvsusm.Mui-disabled{background-color:transparent;color:rgba(0, 0, 0, 0.26);}@media (min-width:1200px){.css-1mvsusm{;}}</style><style data-emotion="css jwr93t">.css-jwr93t{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;position:relative;box-sizing:border-box;-webkit-tap-highlight-color:transparent;background-color:transparent;outline:0;border:0;margin:0;border-radius:0;padding:0;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;-moz-appearance:none;-webkit-appearance:none;-webkit-text-decoration:none;text-decoration:none;color:inherit;text-align:center;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;font-size:1.5rem;padding:8px;border-radius:50%;overflow:visible;color:rgba(0, 0, 0, 0.54);-webkit-transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;color:inherit;}.css-jwr93t::-moz-focus-inner{border-style:none;}.css-jwr93t.Mui-disabled{pointer-events:none;cursor:default;}@media print{.css-jwr93t{-webkit-print-color-adjust:exact;color-adjust:exact;}}.css-jwr93t:hover{background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-jwr93t:hover{background-color:transparent;}}.css-jwr93t.Mui-disabled{background-color:transparent;color:rgba(0, 0, 0, 0.26);}@media (min-width:1200px){.css-jwr93t{;}}</style><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-jwr93t" tabindex="0" type="button"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-vubbuv" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="LanguageIcon"><path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95c-.32-1.25-.78-2.45-1.38-3.56 1.84.63 3.37 1.91 4.33 3.56zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2 0 .68.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56-1.84-.63-3.37-1.9-4.33-3.56zm2.95-8H5.08c.96-1.66 2.49-2.93 4.33-3.56C8.81 5.55 8.35 6.75 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2 0-.68.07-1.35.16-2h4.68c.09.65.16 1.32.16 2 0 .68-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95c-.96 1.65-2.49 2.93-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2 0-.68-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z"/></svg></button><style data-emotion="css t5gsfy">.css-t5gsfy{text-transform:none;font-family:-apple-system,"Poppins","Helvetica Neue",sans-serif,"Noto Sans","Fira Code","IBM Plex Sans","sans-serif";font-weight:500;font-size:0.875rem;line-height:1.75;min-width:64px;padding:6px 8px;border-radius:4px;-webkit-transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;color:inherit;border-color:currentColor;box-shadow:none;}.css-t5gsfy:hover{-webkit-text-decoration:none;text-decoration:none;background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-t5gsfy:hover{background-color:transparent;}}.css-t5gsfy.Mui-disabled{color:rgba(0, 0, 0, 0.26);}.css-t5gsfy:hover{box-shadow:none;}.css-t5gsfy.Mui-focusVisible{box-shadow:none;}.css-t5gsfy:active{box-shadow:none;}.css-t5gsfy.Mui-disabled{box-shadow:none;}@media (min-width:0px){.css-t5gsfy{;}}@media (min-width:1200px){.css-t5gsfy{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;}}</style><style data-emotion="css 1csz7wa">.css-1csz7wa{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;position:relative;box-sizing:border-box;-webkit-tap-highlight-color:transparent;background-color:transparent;outline:0;border:0;margin:0;border-radius:0;padding:0;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;-moz-appearance:none;-webkit-appearance:none;-webkit-text-decoration:none;text-decoration:none;color:inherit;text-transform:none;font-family:-apple-system,"Poppins","Helvetica Neue",sans-serif,"Noto Sans","Fira Code","IBM Plex Sans","sans-serif";font-weight:500;font-size:0.875rem;line-height:1.75;min-width:64px;padding:6px 8px;border-radius:4px;-webkit-transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;color:inherit;border-color:currentColor;box-shadow:none;}.css-1csz7wa::-moz-focus-inner{border-style:none;}.css-1csz7wa.Mui-disabled{pointer-events:none;cursor:default;}@media print{.css-1csz7wa{-webkit-print-color-adjust:exact;color-adjust:exact;}}.css-1csz7wa:hover{-webkit-text-decoration:none;text-decoration:none;background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-1csz7wa:hover{background-color:transparent;}}.css-1csz7wa.Mui-disabled{color:rgba(0, 0, 0, 0.26);}.css-1csz7wa:hover{box-shadow:none;}.css-1csz7wa.Mui-focusVisible{box-shadow:none;}.css-1csz7wa:active{box-shadow:none;}.css-1csz7wa.Mui-disabled{box-shadow:none;}@media (min-width:0px){.css-1csz7wa{;}}@media (min-width:1200px){.css-1csz7wa{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;}}</style><button class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textInherit MuiButton-sizeMedium MuiButton-textSizeMedium MuiButton-colorInherit MuiButton-disableElevation css-1csz7wa" tabindex="0" type="button" id="header-lang-switch" aria-haspopup="true"><span class="MuiButton-startIcon MuiButton-iconSizeMedium css-6xugel"><style data-emotion="css 1slalk2">.css-1slalk2{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:1em;height:1em;display:inline-block;fill:currentColor;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;font-size:1.5rem;fill:#282a36;}</style><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1slalk2" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="LanguageIcon"><path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95c-.32-1.25-.78-2.45-1.38-3.56 1.84.63 3.37 1.91 4.33 3.56zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2 0 .68.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56-1.84-.63-3.37-1.9-4.33-3.56zm2.95-8H5.08c.96-1.66 2.49-2.93 4.33-3.56C8.81 5.55 8.35 6.75 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2 0-.68.07-1.35.16-2h4.68c.09.65.16 1.32.16 2 0 .68-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95c-.96 1.65-2.49 2.93-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2 0-.68-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z"/></svg></span><style data-emotion="css 15r93eu">.css-15r93eu{margin:0;font-size:1rem;line-height:1.5rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:#666666;color:inherit;}</style><span class="MuiTypography-root MuiTypography-body1 css-15r93eu">语言</span><span class="MuiButton-endIcon MuiButton-iconSizeMedium css-1n4a93h"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1slalk2" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="KeyboardArrowDownIcon"><path d="M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z"/></svg></span></button></div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-iuftj9" tabindex="0" type="button"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-vubbuv" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="SearchIcon"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg></button><style data-emotion="css ahtg4s">.css-ahtg4s{max-width:13rem;}@media (min-width:0px){.css-ahtg4s{;}}@media (min-width:1200px){.css-ahtg4s{display:block;}}</style><form class="MuiBox-root css-ahtg4s" novalidate="" autocomplete="off"><style data-emotion="css 24u6h2">.css-24u6h2 .MuiOutlinedInput-root:hover fieldset{border-color:#0ca6f2;border-width:1px;}.css-24u6h2 .MuiOutlinedInput-root.Mui-focused fieldset{border-color:#0ca6f2;border-width:1px;}</style><style data-emotion="css fzbqas">.css-fzbqas .MuiOutlinedInput-root:hover fieldset{border-color:#0ca6f2;border-width:1px;}.css-fzbqas .MuiOutlinedInput-root.Mui-focused fieldset{border-color:#0ca6f2;border-width:1px;}</style><style data-emotion="css bj7gct">.css-bj7gct{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;position:relative;min-width:0;padding:0;margin:0;border:0;vertical-align:top;width:100%;}.css-bj7gct .MuiOutlinedInput-root:hover fieldset{border-color:#0ca6f2;border-width:1px;}.css-bj7gct .MuiOutlinedInput-root.Mui-focused fieldset{border-color:#0ca6f2;border-width:1px;}</style><div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-bj7gct"><style data-emotion="css-global 1prfaxn">@-webkit-keyframes mui-auto-fill{from{display:block;}}@keyframes mui-auto-fill{from{display:block;}}@-webkit-keyframes mui-auto-fill-cancel{from{display:block;}}@keyframes mui-auto-fill-cancel{from{display:block;}}</style><style data-emotion="css sv5gtw">.css-sv5gtw{font-size:1rem;line-height:1.4375em;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:rgba(0, 0, 0, 0.87);box-sizing:border-box;position:relative;cursor:text;display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;width:100%;position:relative;border-radius:4px;padding-left:14px;background:#fff;}.css-sv5gtw.Mui-disabled{color:rgba(0, 0, 0, 0.38);cursor:default;}.css-sv5gtw:hover .MuiOutlinedInput-notchedOutline{border-color:rgba(0, 0, 0, 0.87);}@media (hover: none){.css-sv5gtw:hover .MuiOutlinedInput-notchedOutline{border-color:rgba(0, 0, 0, 0.23);}}.css-sv5gtw.Mui-focused .MuiOutlinedInput-notchedOutline{border-color:#1976d2;border-width:2px;}.css-sv5gtw.Mui-error .MuiOutlinedInput-notchedOutline{border-color:#d32f2f;}.css-sv5gtw.Mui-disabled .MuiOutlinedInput-notchedOutline{border-color:rgba(0, 0, 0, 0.26);}</style><div class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-colorPrimary MuiInputBase-fullWidth MuiInputBase-formControl MuiInputBase-sizeSmall MuiInputBase-adornedStart css-sv5gtw"><style data-emotion="css 1a6giau">.css-1a6giau{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;height:0.01em;max-height:2em;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;white-space:nowrap;color:rgba(0, 0, 0, 0.54);margin-right:8px;}</style><div class="MuiInputAdornment-root MuiInputAdornment-positionStart MuiInputAdornment-outlined MuiInputAdornment-sizeSmall css-1a6giau"><span class="notranslate"></span><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-vubbuv" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="SearchIcon"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg></div><style data-emotion="css f2zrvi">.css-f2zrvi{font:inherit;letter-spacing:inherit;color:currentColor;padding:4px 0 5px;border:0;box-sizing:content-box;background:none;height:1.4375em;margin:0;-webkit-tap-highlight-color:transparent;display:block;min-width:0;width:100%;-webkit-animation-name:mui-auto-fill-cancel;animation-name:mui-auto-fill-cancel;-webkit-animation-duration:10ms;animation-duration:10ms;padding-top:1px;-moz-appearance:textfield;padding:8.5px 14px;padding-left:0;}.css-f2zrvi::-webkit-input-placeholder{color:currentColor;opacity:0.42;-webkit-transition:opacity 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:opacity 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;}.css-f2zrvi::-moz-placeholder{color:currentColor;opacity:0.42;-webkit-transition:opacity 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:opacity 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;}.css-f2zrvi:-ms-input-placeholder{color:currentColor;opacity:0.42;-webkit-transition:opacity 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:opacity 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;}.css-f2zrvi::-ms-input-placeholder{color:currentColor;opacity:0.42;-webkit-transition:opacity 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:opacity 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;}.css-f2zrvi:focus{outline:0;}.css-f2zrvi:invalid{box-shadow:none;}.css-f2zrvi::-webkit-search-decoration{-webkit-appearance:none;}label[data-shrink=false]+.MuiInputBase-formControl .css-f2zrvi::-webkit-input-placeholder{opacity:0!important;}label[data-shrink=false]+.MuiInputBase-formControl .css-f2zrvi::-moz-placeholder{opacity:0!important;}label[data-shrink=false]+.MuiInputBase-formControl .css-f2zrvi:-ms-input-placeholder{opacity:0!important;}label[data-shrink=false]+.MuiInputBase-formControl .css-f2zrvi::-ms-input-placeholder{opacity:0!important;}label[data-shrink=false]+.MuiInputBase-formControl .css-f2zrvi:focus::-webkit-input-placeholder{opacity:0.42;}label[data-shrink=false]+.MuiInputBase-formControl .css-f2zrvi:focus::-moz-placeholder{opacity:0.42;}label[data-shrink=false]+.MuiInputBase-formControl .css-f2zrvi:focus:-ms-input-placeholder{opacity:0.42;}label[data-shrink=false]+.MuiInputBase-formControl .css-f2zrvi:focus::-ms-input-placeholder{opacity:0.42;}.css-f2zrvi.Mui-disabled{opacity:1;-webkit-text-fill-color:rgba(0, 0, 0, 0.38);}.css-f2zrvi:-webkit-autofill{-webkit-animation-duration:5000s;animation-duration:5000s;-webkit-animation-name:mui-auto-fill;animation-name:mui-auto-fill;}.css-f2zrvi:-webkit-autofill{border-radius:inherit;}</style><input type="search" aria-invalid="false" id="doc-search" placeholder="搜索文档" value="" class="MuiInputBase-input MuiOutlinedInput-input MuiInputBase-inputTypeSearch MuiInputBase-inputSizeSmall MuiInputBase-inputAdornedStart css-f2zrvi"/><style data-emotion="css 19w1uun">.css-19w1uun{border-color:rgba(0, 0, 0, 0.23);}</style><style data-emotion="css igs3ac">.css-igs3ac{text-align:left;bottom:0;right:0;top:-5px;left:0;margin:0;padding:0 8px;pointer-events:none;border-radius:inherit;border-style:solid;border-width:1px;overflow:hidden;min-width:0%;border-color:rgba(0, 0, 0, 0.23);}</style><fieldset aria-hidden="true" class="MuiOutlinedInput-notchedOutline css-igs3ac"><style data-emotion="css hdw1oc">.css-hdw1oc{float:unset;overflow:hidden;padding:0;line-height:11px;-webkit-transition:width 150ms cubic-bezier(0.0, 0, 0.2, 1) 0ms;transition:width 150ms cubic-bezier(0.0, 0, 0.2, 1) 0ms;}</style><legend class="css-hdw1oc"><span class="notranslate"></span></legend></fieldset></div></div></form></div></div></header><style data-emotion="css s1brf2">.css-s1brf2{margin-top:5rem;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}</style><div class="PingCAP-Doc MuiBox-root css-s1brf2"><style data-emotion="css hboir5">.css-hboir5{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;width:100%;}</style><div class="MuiBox-root css-hboir5"><style data-emotion="css 2tzg8">.css-2tzg8{width:18.75rem;border-right:1px solid #E5E4E4;}@media (min-width:0px){.css-2tzg8{;}}@media (min-width:1200px){.css-2tzg8{display:block;}}</style><aside class="MuiBox-root css-2tzg8"><style data-emotion="css 1eohm8p">.css-1eohm8p{position:-webkit-sticky;position:sticky;top:5rem;height:100%;max-height:calc(100vh - 7rem);overflow-y:auto;padding:1rem;}</style><div class="MuiBox-root css-1eohm8p"><style data-emotion="css fmyu0n">.css-fmyu0n{text-transform:none;font-family:-apple-system,"Poppins","Helvetica Neue",sans-serif,"Noto Sans","Fira Code","IBM Plex Sans","sans-serif";font-weight:500;font-size:0.875rem;line-height:1.75;min-width:64px;padding:6px 8px;border-radius:4px;-webkit-transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;color:#1976d2;width:100%;height:2rem;-webkit-box-pack:justify;-webkit-justify-content:space-between;justify-content:space-between;border-style:solid;border-width:1px;border-color:#e5e5e5;margin-bottom:1rem;}.css-fmyu0n:hover{-webkit-text-decoration:none;text-decoration:none;background-color:rgba(25, 118, 210, 0.04);}@media (hover: none){.css-fmyu0n:hover{background-color:transparent;}}.css-fmyu0n.Mui-disabled{color:rgba(0, 0, 0, 0.26);}</style><style data-emotion="css 1rq233s">.css-1rq233s{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;position:relative;box-sizing:border-box;-webkit-tap-highlight-color:transparent;background-color:transparent;outline:0;border:0;margin:0;border-radius:0;padding:0;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;-moz-appearance:none;-webkit-appearance:none;-webkit-text-decoration:none;text-decoration:none;color:inherit;text-transform:none;font-family:-apple-system,"Poppins","Helvetica Neue",sans-serif,"Noto Sans","Fira Code","IBM Plex Sans","sans-serif";font-weight:500;font-size:0.875rem;line-height:1.75;min-width:64px;padding:6px 8px;border-radius:4px;-webkit-transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;color:#1976d2;width:100%;height:2rem;-webkit-box-pack:justify;-webkit-justify-content:space-between;justify-content:space-between;border-style:solid;border-width:1px;border-color:#e5e5e5;margin-bottom:1rem;}.css-1rq233s::-moz-focus-inner{border-style:none;}.css-1rq233s.Mui-disabled{pointer-events:none;cursor:default;}@media print{.css-1rq233s{-webkit-print-color-adjust:exact;color-adjust:exact;}}.css-1rq233s:hover{-webkit-text-decoration:none;text-decoration:none;background-color:rgba(25, 118, 210, 0.04);}@media (hover: none){.css-1rq233s:hover{background-color:transparent;}}.css-1rq233s.Mui-disabled{color:rgba(0, 0, 0, 0.26);}</style><button class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium css-1rq233s" tabindex="0" type="button" id="version-select-button" aria-haspopup="true"><style data-emotion="css 3cb5vr">.css-3cb5vr{margin:0;font-size:1rem;line-height:1.5rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:#666666;padding:0 0.25rem;font-size:0.875rem;line-height:1.25rem;}</style><div class="MuiTypography-root MuiTypography-body1 css-3cb5vr">v7.5</div><style data-emotion="css 1n4a93h">.css-1n4a93h{display:inherit;margin-right:-4px;margin-left:8px;}.css-1n4a93h>*:nth-of-type(1){font-size:20px;}</style><span class="MuiButton-endIcon MuiButton-iconSizeMedium css-1n4a93h"><style data-emotion="css b5l66">.css-b5l66{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:1em;height:1em;display:inline-block;fill:currentColor;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;font-size:1.5rem;-webkit-transform:rotate(0deg);-moz-transform:rotate(0deg);-ms-transform:rotate(0deg);transform:rotate(0deg);height:1.5rem;width:1.5rem;fill:#999999;margin-right:0.25rem;}</style><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-b5l66" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></span></button><style data-emotion="css 1c58svf">.css-1c58svf .MuiPaper-root{border-radius:6px;margin-top:8px;min-width:268px;color:rgb(55, 65, 81);box-shadow:rgb(255, 255, 255) 0px 0px 0px 0px,rgba(0, 0, 0, 0.05) 0px 0px 0px 1px,rgba(0, 0, 0, 0.1) 0px 10px 15px -3px,rgba(0, 0, 0, 0.05) 0px 4px 6px -2px;}.css-1c58svf .MuiPaper-root .MuiMenu-list{padding:4px 0;}.css-1c58svf .MuiPaper-root .MuiMenuItem-root .MuiSvgIcon-root{font-size:18px;color:rgba(0, 0, 0, 0.6);margin-right:12px;}.css-1c58svf .MuiPaper-root .MuiMenuItem-root:active{background-color:rgba(25, 118, 210, 0.08);}</style><style data-emotion="css yvxbj">.css-yvxbj .MuiPaper-root{border-radius:6px;margin-top:8px;min-width:268px;color:rgb(55, 65, 81);box-shadow:rgb(255, 255, 255) 0px 0px 0px 0px,rgba(0, 0, 0, 0.05) 0px 0px 0px 1px,rgba(0, 0, 0, 0.1) 0px 10px 15px -3px,rgba(0, 0, 0, 0.05) 0px 4px 6px -2px;}.css-yvxbj .MuiPaper-root .MuiMenu-list{padding:4px 0;}.css-yvxbj .MuiPaper-root .MuiMenuItem-root .MuiSvgIcon-root{font-size:18px;color:rgba(0, 0, 0, 0.6);margin-right:12px;}.css-yvxbj .MuiPaper-root .MuiMenuItem-root:active{background-color:rgba(25, 118, 210, 0.08);}</style><style data-emotion="css oe3wem">.css-oe3wem .MuiPaper-root{border-radius:6px;margin-top:8px;min-width:268px;color:rgb(55, 65, 81);box-shadow:rgb(255, 255, 255) 0px 0px 0px 0px,rgba(0, 0, 0, 0.05) 0px 0px 0px 1px,rgba(0, 0, 0, 0.1) 0px 10px 15px -3px,rgba(0, 0, 0, 0.05) 0px 4px 6px -2px;}.css-oe3wem .MuiPaper-root .MuiMenu-list{padding:4px 0;}.css-oe3wem .MuiPaper-root .MuiMenuItem-root .MuiSvgIcon-root{font-size:18px;color:rgba(0, 0, 0, 0.6);margin-right:12px;}.css-oe3wem .MuiPaper-root .MuiMenuItem-root:active{background-color:rgba(25, 118, 210, 0.08);}</style><style data-emotion="css 12mehxg">.css-12mehxg{padding:0;margin:0;list-style:none;outline:0;}</style><ul role="tree" id="left-nav-treeview" aria-multiselectable="false" class="MuiTreeView-root css-12mehxg" tabindex="0" aria-label="left navigation"><style data-emotion="css 1gesgke">.css-1gesgke .MuiTreeItem-content{color:#282a36;border-radius:4px;}.css-1gesgke .MuiTreeItem-content:hover{background-color:#f9f9f9;}.css-1gesgke .MuiTreeItem-content.Mui-selected,.css-1gesgke .MuiTreeItem-content.Mui-selected.Mui-focused{background-color:var(--tree-view-bg-color, #EAF6FB);color:var(--tree-view-color, #0A85C2);}.css-1gesgke .MuiTreeItem-content.Mui-selected svg.MuiTreeItem-ChevronRightIcon,.css-1gesgke .MuiTreeItem-content.Mui-selected.Mui-focused svg.MuiTreeItem-ChevronRightIcon{fill:var(--tree-view-color, #0A85C2);}.css-1gesgke .MuiTreeItem-content.Mui-focused{background-color:#f9f9f9;}.css-1gesgke .MuiTreeItem-content .MuiTreeItem-label{font-weight:inherit;color:inherit;}.css-1gesgke .MuiTreeItem-content .MuiTreeItem-iconContainer{;}.css-1gesgke .MuiTreeItem-group{margin-left:0;}.css-1gesgke .MuiTreeItem-group .MuiTreeItem-content{padding-left:16px;}</style><style data-emotion="css 1oy5rnm">.css-1oy5rnm{list-style:none;margin:0;padding:0;outline:0;}.css-1oy5rnm .MuiTreeItem-content{color:#282a36;border-radius:4px;}.css-1oy5rnm .MuiTreeItem-content:hover{background-color:#f9f9f9;}.css-1oy5rnm .MuiTreeItem-content.Mui-selected,.css-1oy5rnm .MuiTreeItem-content.Mui-selected.Mui-focused{background-color:var(--tree-view-bg-color, #EAF6FB);color:var(--tree-view-color, #0A85C2);}.css-1oy5rnm .MuiTreeItem-content.Mui-selected svg.MuiTreeItem-ChevronRightIcon,.css-1oy5rnm .MuiTreeItem-content.Mui-selected.Mui-focused svg.MuiTreeItem-ChevronRightIcon{fill:var(--tree-view-color, #0A85C2);}.css-1oy5rnm .MuiTreeItem-content.Mui-focused{background-color:#f9f9f9;}.css-1oy5rnm .MuiTreeItem-content .MuiTreeItem-label{font-weight:inherit;color:inherit;}.css-1oy5rnm .MuiTreeItem-content .MuiTreeItem-iconContainer{;}.css-1oy5rnm .MuiTreeItem-group{margin-left:0;}.css-1oy5rnm .MuiTreeItem-group .MuiTreeItem-content{padding-left:16px;}</style><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-0" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><style data-emotion="css khel7y">.css-khel7y{padding:0 8px;width:100%;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;cursor:pointer;-webkit-tap-highlight-color:transparent;}.css-khel7y:hover{background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-khel7y:hover{background-color:transparent;}}.css-khel7y.Mui-disabled{opacity:0.38;background-color:transparent;}.css-khel7y.Mui-focused{background-color:rgba(0, 0, 0, 0.12);}.css-khel7y.Mui-selected{background-color:rgba(25, 118, 210, 0.08);}.css-khel7y.Mui-selected:hover{background-color:rgba(25, 118, 210, 0.12);}@media (hover: none){.css-khel7y.Mui-selected:hover{background-color:rgba(25, 118, 210, 0.08);}}.css-khel7y.Mui-selected.Mui-focused{background-color:rgba(25, 118, 210, 0.2);}.css-khel7y .MuiTreeItem-iconContainer{margin-right:4px;width:15px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;}.css-khel7y .MuiTreeItem-iconContainer svg{font-size:18px;}.css-khel7y .MuiTreeItem-label{width:100%;min-width:0;padding-left:4px;position:relative;font-size:1rem;line-height:1.5rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:#666666;}</style><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><style data-emotion="css znl8a3">.css-znl8a3{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;min-height:1.75rem;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;padding-left:0rem;padding-top:0.25rem;padding-bottom:0.25rem;}</style><div class="css-znl8a3"><style data-emotion="css tx8jsd">.css-tx8jsd{margin:0;font-size:1rem;line-height:1.5rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:#666666;}</style><a class="MuiTypography-root MuiTypography-body1 css-tx8jsd" target="_blank" href="https://docs.pingcap.com/zh" style="text-decoration:none;width:100%;color:inherit"><style data-emotion="css 8atqhb">.css-8atqhb{width:100%;}</style><div class="MuiBox-root css-8atqhb"><style data-emotion="css 1hwyipb">.css-1hwyipb{margin:0;font-size:1rem;line-height:1.5rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:#666666;color:inherit;font-size:0.875rem;line-height:1.25rem;}</style><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">文档中心</div></div></a></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-1" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">关于 TiDB</div></div><style data-emotion="css xjq79n">.css-xjq79n{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:1em;height:1em;display:inline-block;fill:currentColor;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;font-size:1.5rem;fill:#999999;height:1rem;width:1rem;margin-left:auto;-webkit-transform:none;-moz-transform:none;-ms-transform:none;transform:none;}</style><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div><style data-emotion="css 1jozaee">.css-1jozaee{margin:0;padding:0;margin-left:17px;}</style></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-2" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">快速上手</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-3" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">应用开发</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-4" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">部署标准集群</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-5" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">数据迁移</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-6" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">数据集成</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-7" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">运维操作</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-8" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">监控与告警</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-9" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">故障诊断</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="true" id="left-nav-treeview-0-10" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content Mui-expanded" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">性能调优</div></div><style data-emotion="css 171pefp">.css-171pefp{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:1em;height:1em;display:inline-block;fill:currentColor;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;font-size:1.5rem;fill:#999999;height:1rem;width:1rem;margin-left:auto;-webkit-transform:rotate(90deg);-moz-transform:rotate(90deg);-ms-transform:rotate(90deg);transform:rotate(90deg);}</style><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-171pefp" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div><style data-emotion="css 1xxsnna">.css-1xxsnna{height:auto;overflow:visible;-webkit-transition:height 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:height 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;margin:0;padding:0;margin-left:17px;}</style><ul class="MuiCollapse-root MuiCollapse-vertical MuiTreeItem-group MuiCollapse-entered css-1xxsnna" style="min-height:0px" role="group"><div class="MuiCollapse-wrapper MuiCollapse-vertical css-hboir5"><div class="MuiCollapse-wrapperInner MuiCollapse-vertical css-8atqhb"><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-10-0" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><style data-emotion="css kb2j4b">.css-kb2j4b{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;min-height:1.75rem;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;padding-left:0.5rem;padding-top:0.25rem;padding-bottom:0.25rem;}</style><div class="css-kb2j4b"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">优化手册</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-10-1" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-kb2j4b"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">配置调优</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="true" id="left-nav-treeview-0-10-2" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content Mui-expanded" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-kb2j4b"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">SQL 性能调优</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-171pefp" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div><ul class="MuiCollapse-root MuiCollapse-vertical MuiTreeItem-group MuiCollapse-entered css-1xxsnna" style="min-height:0px" role="group"><div class="MuiCollapse-wrapper MuiCollapse-vertical css-hboir5"><div class="MuiCollapse-wrapperInner MuiCollapse-vertical css-8atqhb"><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-10-2-0" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><style data-emotion="css snygwd">.css-snygwd{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;min-height:1.75rem;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;padding-left:1rem;padding-top:0.25rem;padding-bottom:0.25rem;}</style><div class="css-snygwd"><a style="text-decoration:none;width:100%;color:inherit" href="/zh/tidb/stable/sql-tuning-overview"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">SQL 性能调优概览</div></div></a></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-10-2-1" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-snygwd"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">理解 TiDB 执行计划</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="true" id="left-nav-treeview-0-10-2-2" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content Mui-expanded" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-snygwd"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">SQL 优化流程</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-171pefp" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div><ul class="MuiCollapse-root MuiCollapse-vertical MuiTreeItem-group MuiCollapse-entered css-1xxsnna" style="min-height:0px" role="group"><div class="MuiCollapse-wrapper MuiCollapse-vertical css-hboir5"><div class="MuiCollapse-wrapperInner MuiCollapse-vertical css-8atqhb"><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-10-2-2-0" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><style data-emotion="css 5fc025">.css-5fc025{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;min-height:1.75rem;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;padding-left:1.5rem;padding-top:0.25rem;padding-bottom:0.25rem;}</style><div class="css-5fc025"><a style="text-decoration:none;width:100%;color:inherit" href="/zh/tidb/stable/sql-optimization-concepts"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">SQL 优化流程概览</div></div></a></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-10-2-2-1" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-5fc025"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">逻辑优化</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="true" id="left-nav-treeview-0-10-2-2-2" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content Mui-expanded" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-5fc025"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">物理优化</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-171pefp" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div><ul class="MuiCollapse-root MuiCollapse-vertical MuiTreeItem-group MuiCollapse-entered css-1xxsnna" style="min-height:0px" role="group"><div class="MuiCollapse-wrapper MuiCollapse-vertical css-hboir5"><div class="MuiCollapse-wrapperInner MuiCollapse-vertical css-8atqhb"><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-10-2-2-2-0" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><style data-emotion="css 108qnny">.css-108qnny{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;min-height:1.75rem;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;padding-left:2rem;padding-top:0.25rem;padding-bottom:0.25rem;}</style><div class="css-108qnny"><a style="text-decoration:none;width:100%;color:inherit" href="/zh/tidb/stable/sql-physical-optimization"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">物理优化概览</div></div></a></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-10-2-2-2-1" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-108qnny"><a style="text-decoration:none;width:100%;color:inherit" href="/zh/tidb/stable/choose-index"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">索引的选择</div></div></a></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-10-2-2-2-2" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content Mui-expanded" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-108qnny"><a aria-current="page" style="text-decoration:none;width:100%;color:inherit" class="" href="/zh/tidb/stable/statistics"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">统计信息简介</div></div></a></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-10-2-2-2-3" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-108qnny"><a style="text-decoration:none;width:100%;color:inherit" href="/zh/tidb/stable/wrong-index-solution"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">错误索引的解决方案</div></div></a></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-10-2-2-2-4" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-108qnny"><a style="text-decoration:none;width:100%;color:inherit" href="/zh/tidb/stable/agg-distinct-optimization"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">Distinct 优化</div></div></a></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-10-2-2-2-5" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-108qnny"><a style="text-decoration:none;width:100%;color:inherit" href="/zh/tidb/stable/cost-model"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">代价模型</div></div></a></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-10-2-2-2-6" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-108qnny"><a style="text-decoration:none;width:100%;color:inherit" href="/zh/tidb/stable/runtime-filter"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">Runtime Filter</div></div></a></div></div></div></li></div></div></ul></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-10-2-2-3" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-5fc025"><a style="text-decoration:none;width:100%;color:inherit" href="/zh/tidb/stable/sql-prepared-plan-cache"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">Prepare 语句执行计划缓存</div></div></a></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-10-2-2-4" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-5fc025"><a style="text-decoration:none;width:100%;color:inherit" href="/zh/tidb/stable/sql-non-prepared-plan-cache"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">非 Prepare 语句执行计划缓存</div></div></a></div></div></div></li></div></div></ul></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-10-2-3" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-snygwd"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">控制执行计划</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li></div></div></ul></li></div></div></ul></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-11" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">教程</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-12" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">TiDB 工具</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-13" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">参考指南</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-14" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">常见问题解答 (FAQ)</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" aria-expanded="false" id="left-nav-treeview-0-15" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">版本发布历史</div></div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTreeItem-ChevronRightIcon css-xjq79n" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ChevronRightIcon"><path d="M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></div></div></div></li><li class="MuiTreeItem-root css-1oy5rnm" role="treeitem" id="left-nav-treeview-0-16" tabindex="-1" style="margin-top:0.1875rem;margin-bottom:0.1875rem"><div class="css-khel7y MuiTreeItem-content" style="width:inherit"><div class="MuiTreeItem-iconContainer"/><div class="MuiTreeItem-label"><div class="css-znl8a3"><a style="text-decoration:none;width:100%;color:inherit" href="/zh/tidb/stable/glossary"><div class="MuiBox-root css-8atqhb"><div class="MuiTypography-root MuiTypography-body1 css-1hwyipb">术语表</div></div></a></div></div></div></li></ul></div></aside><style data-emotion="css sb2sd0">.css-sb2sd0{width:100%;}@media (min-width:1200px){.css-sb2sd0{max-width:calc(100% - 18.75rem);}}</style><main class="MuiBox-root css-sb2sd0"><style data-emotion="css 1rnnmjb">.css-1rnnmjb{max-width:1340px;width:100%;margin-left:auto;margin-right:auto;display:block;box-sizing:border-box;}</style><div class="MuiBox-root css-1rnnmjb"><style data-emotion="css 90fn5w">.css-90fn5w{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}@media (min-width:0px){.css-90fn5w{-webkit-flex-direction:column-reverse;-ms-flex-direction:column-reverse;flex-direction:column-reverse;}}@media (min-width:600px){.css-90fn5w{-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;}}</style><div class="css-90fn5w"><style data-emotion="css vofosd">.css-vofosd{padding:1.5rem 0;}@media (min-width:0px){.css-vofosd{width:100%;}}@media (min-width:600px){.css-vofosd{width:calc(100% - 17.5rem);}}</style><div class="MuiBox-root css-vofosd"><style data-emotion="css 1ekb41w">.css-1ekb41w{width:100%;margin-left:auto;box-sizing:border-box;margin-right:auto;display:block;padding-left:16px;padding-right:16px;}@media (min-width:600px){.css-1ekb41w{padding-left:24px;padding-right:24px;}}@media (min-width:1536px){.css-1ekb41w{max-width:1536px;}}</style><div class="MuiContainer-root MuiContainer-maxWidthXl doc-content css-1ekb41w"><div class="markdown-body MuiBox-root css-0"><h1 id="统计信息简介" style="position:relative"><a href="#%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%E7%AE%80%E4%BB%8B" aria-label="统计信息简介 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>统计信息简介</h1><p>TiDB 使用统计信息来决定<a href="/zh/tidb/stable/choose-index">索引的选择</a>。</p><h2 id="统计信息版本" style="position:relative"><a href="#%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%E7%89%88%E6%9C%AC" aria-label="统计信息版本 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>统计信息版本</h2><p>变量 <code>tidb_analyze_version</code> 用于控制所收集到的统计信息。目前 TiDB 中支持两种统计信息:<code>tidb_analyze_version = 1</code> 以及 <code>tidb_analyze_version = 2</code>。在 v5.3.0 及之后的版本中,该变量的默认值为 <code>2</code>。如果从 v5.3.0 之前版本的集群升级至 v5.3.0 及之后的版本,<code>tidb_analyze_version</code> 的默认值不发生变化。</p><p>Version 2 的统计信息避免了 Version 1 中因为哈希冲突导致的在较大的数据量中可能产生的较大误差,并保持了大多数场景中的估算精度。</p><p>两种版本中,TiDB 维护的统计信息如下:</p><table><thead><tr><th>信息</th><th>Version 1</th><th>Version 2</th></tr></thead><tbody><tr><td>表的总行数</td><td>√</td><td>√</td></tr><tr><td>列的 Count-Min Sketch</td><td>√</td><td>×</td></tr><tr><td>索引的 Count-Min Sketch</td><td>√</td><td>×</td></tr><tr><td>列的 Top-N</td><td>√</td><td>√(改善了维护方式和精度)</td></tr><tr><td>索引的 Top-N</td><td>√(维护精度不足,会产生较大误差)</td><td>√(改善了维护方式和精度)</td></tr><tr><td>列的直方图</td><td>√</td><td>√(直方图中不包含 Top-N 中出现的值)</td></tr><tr><td>索引的直方图</td><td>√</td><td>√(直方图的桶中记录了各自的不同值的个数,且直方图不包含 Top-N 中出现的值)</td></tr><tr><td>列的 NULL 值个数</td><td>√</td><td>√</td></tr><tr><td>索引的 NULL 值个数</td><td>√</td><td>√</td></tr><tr><td>列的平均长度</td><td>√</td><td>√</td></tr><tr><td>索引的平均长度</td><td>√</td><td>√</td></tr></tbody></table><p>当 <code>tidb_analyze_version = 2</code> 时,如果执行 ANALYZE 语句后发生 OOM,需要设置全局变量 <code>tidb_analyze_version = 1</code>,回退到 Version 1,然后根据情况进行以下操作:</p><ul><li><p>如果 ANALYZE 语句是手动执行的,你需要手动 ANALYZE 每张需要的表:</p><pre><code class="hljs language-sql"><style data-emotion="css 1qhimia">.css-1qhimia{margin-right:3rem;overflow:auto;}</style><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DISTINCT</span>(CONCAT(<span class="hljs-string">'ANALYZE TABLE '</span>, table_schema, <span class="hljs-string">'.'</span>, table_name, <span class="hljs-string">';'</span>)) <span class="hljs-keyword">FROM</span> information_schema.tables, mysql.stats_histograms <span class="hljs-keyword">WHERE</span> stats_ver <span class="hljs-operator">=</span> <span class="hljs-number">2</span> <span class="hljs-keyword">AND</span> table_id <span class="hljs-operator">=</span> tidb_table_id; </div><style data-emotion="css ux9q70">.css-ux9q70{text-align:center;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;font-size:1.5rem;padding:8px;border-radius:50%;overflow:visible;color:rgba(0, 0, 0, 0.54);-webkit-transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;padding:5px;font-size:1.125rem;top:0.625rem;right:2.4rem;background:transparent;border:unset;}.css-ux9q70:hover{background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-ux9q70:hover{background-color:transparent;}}.css-ux9q70.Mui-disabled{background-color:transparent;color:rgba(0, 0, 0, 0.26);}</style><style data-emotion="css 1rmx1rm">.css-1rmx1rm{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;position:relative;box-sizing:border-box;-webkit-tap-highlight-color:transparent;background-color:transparent;outline:0;border:0;margin:0;border-radius:0;padding:0;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;-moz-appearance:none;-webkit-appearance:none;-webkit-text-decoration:none;text-decoration:none;color:inherit;text-align:center;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;font-size:1.5rem;padding:8px;border-radius:50%;overflow:visible;color:rgba(0, 0, 0, 0.54);-webkit-transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;padding:5px;font-size:1.125rem;top:0.625rem;right:2.4rem;background:transparent;border:unset;}.css-1rmx1rm::-moz-focus-inner{border-style:none;}.css-1rmx1rm.Mui-disabled{pointer-events:none;cursor:default;}@media print{.css-1rmx1rm{-webkit-print-color-adjust:exact;color-adjust:exact;}}.css-1rmx1rm:hover{background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-1rmx1rm:hover{background-color:transparent;}}.css-1rmx1rm.Mui-disabled{background-color:transparent;color:rgba(0, 0, 0, 0.26);}</style><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><style data-emotion="css 1cw4hi4">.css-1cw4hi4{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:1em;height:1em;display:inline-block;fill:currentColor;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;font-size:inherit;}</style><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><style data-emotion="css 1e2dcm1">.css-1e2dcm1{z-index:1500;pointer-events:none;}</style><style data-emotion="css okvapm">.css-okvapm{z-index:1500;pointer-events:none;}</style><style data-emotion="css rnn29l">.css-rnn29l{text-align:center;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;font-size:1.5rem;padding:8px;border-radius:50%;overflow:visible;color:rgba(0, 0, 0, 0.54);-webkit-transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;padding:5px;font-size:1.125rem;top:0.625rem;right:0.625rem;background:transparent;border:unset;}.css-rnn29l:hover{background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-rnn29l:hover{background-color:transparent;}}.css-rnn29l.Mui-disabled{background-color:transparent;color:rgba(0, 0, 0, 0.26);}</style><style data-emotion="css fxo539">.css-fxo539{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;position:relative;box-sizing:border-box;-webkit-tap-highlight-color:transparent;background-color:transparent;outline:0;border:0;margin:0;border-radius:0;padding:0;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;-moz-appearance:none;-webkit-appearance:none;-webkit-text-decoration:none;text-decoration:none;color:inherit;text-align:center;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;font-size:1.5rem;padding:8px;border-radius:50%;overflow:visible;color:rgba(0, 0, 0, 0.54);-webkit-transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;padding:5px;font-size:1.125rem;top:0.625rem;right:0.625rem;background:transparent;border:unset;}.css-fxo539::-moz-focus-inner{border-style:none;}.css-fxo539.Mui-disabled{pointer-events:none;cursor:default;}@media print{.css-fxo539{-webkit-print-color-adjust:exact;color-adjust:exact;}}.css-fxo539:hover{background-color:rgba(0, 0, 0, 0.04);}@media (hover: none){.css-fxo539:hover{background-color:transparent;}}.css-fxo539.Mui-disabled{background-color:transparent;color:rgba(0, 0, 0, 0.26);}</style><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre></li><li><p>如果 ANALYZE 语句是开启了自动 ANALYZE 后 TiDB 自动执行的,使用以下 SQL 语句生成 DROP STATS 的语句并执行:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DISTINCT</span>(CONCAT(<span class="hljs-string">'DROP STATS '</span>, table_schema, <span class="hljs-string">'.'</span>, table_name, <span class="hljs-string">';'</span>)) <span class="hljs-keyword">FROM</span> information_schema.tables, mysql.stats_histograms <span class="hljs-keyword">WHERE</span> stats_ver <span class="hljs-operator">=</span> <span class="hljs-number">2</span> <span class="hljs-keyword">AND</span> table_id <span class="hljs-operator">=</span> tidb_table_id; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre></li><li><p>如果上一条语句返回结果太长,不方便复制粘贴,可以将结果导出到临时文件后,再执行:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SELECT</span> DISTINCT... <span class="hljs-keyword">INTO</span> outfile <span class="hljs-string">'/tmp/sql.txt'</span>; mysql <span class="hljs-operator">-</span>h ${TiDB_IP} <span class="hljs-operator">-</span>u <span class="hljs-keyword">user</span> <span class="hljs-operator">-</span>P ${TIDB_PORT} ... <span class="hljs-operator"><</span> <span class="hljs-string">'/tmp/sql.txt'</span>; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre></li></ul><p>本文接下来将简单介绍其中出现的直方图和 Count-Min Sketch 以及 Top-N 这些数据结构,以及详细介绍统计信息的收集和维护。</p><h2 id="直方图简介" style="position:relative"><a href="#%E7%9B%B4%E6%96%B9%E5%9B%BE%E7%AE%80%E4%BB%8B" aria-label="直方图简介 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>直方图简介</h2><p>直方图是一种对数据分布情况进行描述的工具,它会按照数据的值大小进行分桶,并用一些简单的数据来描述每个桶,比如落在桶里的值的个数。在 TiDB 中,会对每个表具体的列构建一个等深直方图,区间查询的估算便是借助该直方图来进行。</p><p>等深直方图,就是让落入每个桶里的值数量尽量相等。举个例子,比方说对于给定的集合 {1.6, 1.9, 1.9, 2.0, 2.4, 2.6, 2.7, 2.7, 2.8, 2.9, 3.4, 3.5},并且生成 4 个桶,那么最终的等深直方图就会如下图所示,包含四个桶 <!-- -->[1.6, 1.9]<!-- -->,<!-- -->[2.0, 2.6]<!-- -->,<!-- -->[2.7, 2.8]<!-- -->,<!-- -->[2.9, 3.5]<!-- -->,其桶深均为 3。</p><p><img src="https://download.pingcap.com/images/docs-cn/statistics-1.png" alt="等深直方图示例"/></p><p>在<a href="#%E6%89%8B%E5%8A%A8%E6%94%B6%E9%9B%86">手动收集统计信息</a>一节中有控制直方图桶数量上限的参数。当桶数量越多,直方图的估算精度就越高,不过也会同时增大统计信息的内存使用,可以视具体情况来做调整。</p><h2 id="count-min-sketch" style="position:relative"><a href="#count-min-sketch" aria-label="count min sketch permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>Count-Min Sketch</h2><p>Count-Min Sketch 是一种哈希结构,当查询中出现诸如 <code>a = 1</code> 或者 <code>IN</code> 查询(如 <code>a in (1, 2, 3)</code>)这样的等值查询时,TiDB 便会使用这个数据结构来进行估算。</p><p>由于 Count-Min Sketch 是一个哈希结构,就有出现哈希碰撞的可能。当在 <code>EXPLAIN</code> 语句中发现等值查询的估算偏离实际值较大时,就可以认为是一个比较大的值和一个比较小的值被哈希到了一起。这时有以下两种手段来避免这个情况:</p><ul><li>修改<a href="#%E6%89%8B%E5%8A%A8%E6%94%B6%E9%9B%86">手动收集统计信息</a>中提到的 <code>WITH NUM TOPN</code> 参数。TiDB 会将出现频率前 x 大的数据单独储存,之后的数据再储存到 Count-Min Sketch 中。因此可以调大这个值来避免一个比较大的值和一个比较小的值被哈希到一起。在 TiDB 中,这个参数的默认值是 20,最大可以设置为 1024。</li><li>修改<a href="#%E6%89%8B%E5%8A%A8%E6%94%B6%E9%9B%86">统计信息的收集-手动收集</a>中提到的 <code>WITH NUM CMSKETCH DEPTH</code> 和 <code>WITH NUM CMSKETCH WIDTH</code> 两个参数,这两个参数会影响哈希的桶数和碰撞概率,可是适当调大来减少冲突概率,同时它会影响统计信息的内存使用,可以视具体情况来调整。在 TiDB 中,<code>DEPTH</code> 的默认值是 5,<code>WIDTH</code> 的默认值是 2048。</li></ul><h2 id="top-n-values" style="position:relative"><a href="#top-n-values" aria-label="top n values permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>Top-N values</h2><p>Top-N 即是这个列或者这个索引中,出现次数前 n 的值。TiDB 会记录前 n 个值的具体的值以及出现次数。</p><h2 id="统计信息的收集" style="position:relative"><a href="#%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%E7%9A%84%E6%94%B6%E9%9B%86" aria-label="统计信息的收集 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>统计信息的收集</h2><h3 id="手动收集" style="position:relative"><a href="#%E6%89%8B%E5%8A%A8%E6%94%B6%E9%9B%86" aria-label="手动收集 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>手动收集</h3><p>目前 TiDB 收集统计信息为全量收集,通过 <code>ANALYZE TABLE</code> 语句来实现。</p><style data-emotion="css 1weqspv">.css-1weqspv{padding-top:0.5rem;padding-bottom:0.5rem;}.css-1weqspv .MuiAlert-message p{margin-bottom:0px;margin-top:0px;}</style><div class="MuiBox-root css-1weqspv"><style data-emotion="css 17zlexa">.css-17zlexa{font-size:0.875rem;line-height:1.25rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:rgb(1, 67, 97);background-color:rgb(229, 246, 253);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;padding:6px 16px;}.css-17zlexa .MuiAlert-icon{color:#03a9f4;}</style><style data-emotion="css 152gid5">.css-152gid5{background-color:#fff;color:rgba(0, 0, 0, 0.87);-webkit-transition:box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;border-radius:4px;box-shadow:none;font-size:0.875rem;line-height:1.25rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:rgb(1, 67, 97);background-color:rgb(229, 246, 253);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;padding:6px 16px;}.css-152gid5 .MuiAlert-icon{color:#03a9f4;}</style><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardInfo MuiAlert-standard css-152gid5" role="alert"><style data-emotion="css 1l54tgj">.css-1l54tgj{margin-right:12px;padding:7px 0;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:22px;opacity:0.9;}</style><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="InfoOutlinedIcon"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20, 12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10, 10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg></div><style data-emotion="css 1xsto0d">.css-1xsto0d{padding:8px 0;min-width:0;overflow:auto;}</style><div class="MuiAlert-message css-1xsto0d"><style data-emotion="css 1h2y6o4">.css-1h2y6o4{font-weight:500;margin-top:-2px;}</style><style data-emotion="css 17ioyuk">.css-17ioyuk{margin:0;font-size:1rem;line-height:1.5rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:#666666;margin-bottom:0.35em;font-weight:500;margin-top:-2px;}</style><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">注意</div><ul><li>在 TiDB 中执行 <code>ANALYZE TABLE</code> 语句比在 MySQL 或 InnoDB 中耗时更长。InnoDB 采样的只是少量页面,但 TiDB 会完全重构一系列统计信息。适用于 MySQL 的脚本会误以为执行 <code>ANALYZE TABLE</code> 耗时较短。</li><li>从 v7.5.0 开始,统计信息<a href="/zh/tidb/stable/system-variables#tidb_enable_fast_analyze">快速分析 (<code>tidb_enable_fast_analyze</code>)</a> 和<a href="https://docs.pingcap.com/zh/tidb/v7.4/statistics#增量收集" target="_blank" referrerpolicy="no-referrer-when-downgrade">增量收集</a>废弃。</li></ul></div></div></div><p>可以通过以下几种语法进行全量收集。</p><p>收集 TableNameList 中所有表的统计信息:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">ANALYZE <span class="hljs-keyword">TABLE</span> TableNameList [<span class="hljs-keyword">WITH</span> NUM BUCKETS<span class="hljs-operator">|</span>TOPN<span class="hljs-operator">|</span>CMSKETCH DEPTH<span class="hljs-operator">|</span>CMSKETCH WIDTH]<span class="hljs-operator">|</span>[<span class="hljs-keyword">WITH</span> NUM SAMPLES<span class="hljs-operator">|</span><span class="hljs-keyword">WITH</span> FLOATNUM SAMPLERATE]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><ul><li><code>WITH NUM BUCKETS</code> 用于指定生成直方图的桶数量上限。</li><li><code>WITH NUM TOPN</code> 用于指定生成 TOPN 数目的上限。</li><li><code>WITH NUM CMSKETCH DEPTH</code> 用于指定 CM Sketch 的长。</li><li><code>WITH NUM CMSKETCH WIDTH</code> 用于指定 CM Sketch 的宽。</li><li><code>WITH NUM SAMPLES</code> 用于指定采样的数目。</li><li><code>WITH FLOAT_NUM SAMPLERATE</code> 用于指定采样率。</li></ul><p><code>WITH NUM SAMPLES</code> 与 <code>WITH FLOAT_NUM SAMPLERATE</code> 这两种设置对应了两种不同的收集采样的算法。</p><ul><li><code>WITH NUM SAMPLES</code> 指定了采样集的大小,在 TiDB 中是以蓄水池采样的方式实现。当表较大时,不推荐使用这种方式收集统计信息。因为蓄水池采样中间结果集会产生一定的冗余结果,会对内存等资源造成额外的压力。</li><li><code>WITH FLOAT_NUM SAMPLERATE</code> 是在 v5.3.0 中引入的采样方式,指定的采样率的大小,是取值范围 <code>(0, 1]</code> 的参数。在 TiDB 中是以伯努利采样的方式实现,更适合对较大的表进行采样,在收集效率和资源使用上更有优势。</li></ul><p>在 v5.3.0 之前 TiDB 采用蓄水池采样的方式收集统计信息。自 v5.3.0 版本起,TiDB Version 2 的统计信息默认会选取伯努利采样的方式收集统计信息。若要重新使用蓄水池采样的方式采样,可以使用 <code>WITH NUM SAMPLES</code> 语句。</p><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardInfo MuiAlert-standard css-152gid5" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="InfoOutlinedIcon"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20, 12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10, 10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">注意</div><p>目前采样率基于自适应算法进行计算。当你通过 <a href="/zh/tidb/stable/sql-statement-show-stats-meta"><code>SHOW STATS_META</code></a> 可以观察到一个表的行数时,可通过这个行数去计算采集 10 万行所对应的采样率。如果你观察不到这个值,可通过 <a href="/zh/tidb/stable/information-schema-table-storage-stats"><code>TABLE_STORAGE_STATS</code></a> 表的 <code>TABLE_KEYS</code> 列作为另一个参考来计算采样率。</p><p>通常情况下,<code>STATS_META</code> 相对 <code>TABLE_KEYS</code> 更可信,但是通过 <a href="/zh/tidb/stable/tidb-lightning-overview">TiDB Lightning</a> 等方式导入数据结束后,<code>STATS_META</code> 结果是 <code>0</code>。为了处理这个情况,你可以在 <code>STATS_META</code> 的结果远小于 <code>TABLE_KEYS</code> 的结果时,使用 <code>TABLE_KEYS</code> 计算采样率。</p></div></div></div><h4 id="收集部分列的统计信息" style="position:relative"><a href="#%E6%94%B6%E9%9B%86%E9%83%A8%E5%88%86%E5%88%97%E7%9A%84%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF" aria-label="收集部分列的统计信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>收集部分列的统计信息</h4><p>执行 SQL 语句时,优化器在大多数情况下只会用到部分列(例如,<code>WHERE</code>、<code>JOIN</code>、<code>ORDER BY</code>、<code>GROUP BY</code> 子句中出现的列)的统计信息,这些被用到的列称为 <code>PREDICATE COLUMNS</code>。</p><p>如果一个表有很多列,收集所有列的统计信息会有较大的开销。为了降低开销,你可以只收集指定列或者 <code>PREDICATE COLUMNS</code> 的统计信息供优化器使用。</p><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardInfo MuiAlert-standard css-152gid5" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="InfoOutlinedIcon"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20, 12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10, 10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">注意</div><ul><li>收集部分列的统计信息的功能仅适用于 <a href="/zh/tidb/stable/system-variables#tidb_analyze_version-从-v510-版本开始引入"><code>tidb_analyze_version = 2</code></a> 的情况。</li><li>TiDB v7.2.0 引入了系统变量 <a href="/zh/tidb/stable/system-variables#tidb_analyze_skip_column_types-从-v720-版本开始引入"><code>tidb_analyze_skip_column_types</code></a>,该变量可以控制在执行 <code>ANALYZE</code> 命令收集统计信息时,跳过哪些类型的列的统计信息收集。该变量仅适用于 <code>tidb_analyze_version = 2</code> 的情况。</li></ul></div></div></div><ul><li><p>如果要收集指定列的统计信息,请使用以下语法:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">ANALYZE <span class="hljs-keyword">TABLE</span> TableName COLUMNS ColumnNameList [<span class="hljs-keyword">WITH</span> NUM BUCKETS<span class="hljs-operator">|</span>TOPN<span class="hljs-operator">|</span>CMSKETCH DEPTH<span class="hljs-operator">|</span>CMSKETCH WIDTH]<span class="hljs-operator">|</span>[<span class="hljs-keyword">WITH</span> NUM SAMPLES<span class="hljs-operator">|</span><span class="hljs-keyword">WITH</span> FLOATNUM SAMPLERATE]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p> 其中,<code>ColumnNameList</code> 表示指定列的名称列表。如果需要指定多列,请使用用逗号 <code>,</code> 分隔列名。例如, <code>ANALYZE table t columns a, b</code>。该语法除了收集指定表中指定列的统计信息,将同时收集该表中索引列的统计信息以及所有索引的统计信息。</p><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardInfo MuiAlert-standard css-152gid5" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="InfoOutlinedIcon"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20, 12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10, 10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">注意</div><p>该语法为全量收集。例如,在使用该语法收集了 a 列和 b 列的统计信息之后,如果还想要增加收集 c 列的统计信息,需要在语法中同时指定这三列 <code>ANALYZE TABLE t columns a, b, c</code>,而不是只指定新增的那一列 <code>ANALYZE TABLE t COLUMNS c</code>。</p></div></div></div></li><li><p>如果要收集 <code>PREDICATE COLUMNS</code> 的统计信息,请进行以下操作:</p><div class="MuiBox-root css-1weqspv"><style data-emotion="css 1rl2db2">.css-1rl2db2{font-size:0.875rem;line-height:1.25rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:rgb(95, 33, 32);background-color:rgb(253, 237, 237);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;padding:6px 16px;}.css-1rl2db2 .MuiAlert-icon{color:#ef5350;}</style><style data-emotion="css 21rxh6">.css-21rxh6{background-color:#fff;color:rgba(0, 0, 0, 0.87);-webkit-transition:box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;border-radius:4px;box-shadow:none;font-size:0.875rem;line-height:1.25rem;font-family:"Helvetica Neue","sans-serif";font-weight:400;font-style:normal;color:rgb(95, 33, 32);background-color:rgb(253, 237, 237);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;padding:6px 16px;}.css-21rxh6 .MuiAlert-icon{color:#ef5350;}</style><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardError MuiAlert-standard css-21rxh6" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ErrorOutlineIcon"><path d="M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">警告</div><p>收集 <code>PREDICATE COLUMNS</code> 的统计信息目前为实验特性,不建议在生产环境中使用。</p></div></div></div><ol><li><p>设置系统变量 <a href="/zh/tidb/stable/system-variables#tidb_enable_column_tracking-从-v540-版本开始引入"><code>tidb_enable_column_tracking</code></a> 的值为 <code>ON</code> 开启 TiDB 对 <code>PREDICATE COLUMNS</code> 的收集。</p><p>开启后,TiDB 将每隔 100 * <a href="/zh/tidb/stable/tidb-configuration-file#stats-lease"><code>stats-lease</code></a> 时间将 <code>PREDICATE COLUMNS</code> 信息写入系统表 <code>mysql.column_stats_usage</code>。</p></li><li><p>在业务的查询模式稳定以后,使用以下语法收集 <code>PREDICATE COLUMNS</code> 的统计信息。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">ANALYZE <span class="hljs-keyword">TABLE</span> TableName PREDICATE COLUMNS [<span class="hljs-keyword">WITH</span> NUM BUCKETS<span class="hljs-operator">|</span>TOPN<span class="hljs-operator">|</span>CMSKETCH DEPTH<span class="hljs-operator">|</span>CMSKETCH WIDTH]<span class="hljs-operator">|</span>[<span class="hljs-keyword">WITH</span> NUM SAMPLES<span class="hljs-operator">|</span><span class="hljs-keyword">WITH</span> FLOATNUM SAMPLERATE]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>该语法除了收集指定表中 <code>PREDICATE COLUMNS</code> 的统计信息,将同时收集该表中索引列的统计信息以及所有索引的统计信息。</p><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardInfo MuiAlert-standard css-152gid5" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="InfoOutlinedIcon"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20, 12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10, 10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">注意</div><ul><li>如果系统表 <code>mysql.column_stats_usage</code> 中没有关于该表的<code>PREDICATE COLUMNS</code> 记录,执行以上语句会收集该表中所有列的统计信息以及所有索引的统计信息。</li><li>使用该语法收集统计信息后,当执行一种新的类型的 SQL 查询时,优化器可能会暂时使用旧的或者 pseudo 的列统计信息,然后在下一次收集统计信息的时候收集该列的统计信息。</li></ul></div></div></div></li></ol></li><li><p>如果要收集所有列的统计信息以及所有索引的统计信息,可以使用以下语法:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">ANALYZE <span class="hljs-keyword">TABLE</span> TableName <span class="hljs-keyword">ALL</span> COLUMNS [<span class="hljs-keyword">WITH</span> NUM BUCKETS<span class="hljs-operator">|</span>TOPN<span class="hljs-operator">|</span>CMSKETCH DEPTH<span class="hljs-operator">|</span>CMSKETCH WIDTH]<span class="hljs-operator">|</span>[<span class="hljs-keyword">WITH</span> NUM SAMPLES<span class="hljs-operator">|</span><span class="hljs-keyword">WITH</span> FLOATNUM SAMPLERATE]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre></li></ul><p>如果要持久化 <code>ANALYZE</code> 语句中列的配置(包括 <code>COLUMNS ColumnNameList</code>、<code>PREDICATE COLUMNS</code>、<code>ALL COLUMNS</code>),请设置系统变量 <code>tidb_persist_analyze_options</code> 的值设置为 <code>ON</code> 以开启 <a href="/zh/tidb/stable/statistics#analyze-配置持久化">ANALYZE 配置持久化</a>特性。开启 ANALYZE 配置持久化特性后:</p><ul><li>当 TiDB 自动收集统计信息或者你手动执行 <code>ANALYZE</code> 语句收集统计信息但未指定列的配置时,TiDB 会继续沿用之前持久化的配置。</li><li>当多次手动执行 <code>ANALYZE</code> 语句并指定列的配置时,TiDB 会使用最新一次 <code>ANALYZE</code> 指定的配置项覆盖上一次记录的持久化配置。</li></ul><p>如果你想查看一个表中哪些列是 <code>PREDICATE COLUMNS</code>,哪些列的统计信息已经被收集,可以使用以下语法:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SHOW</span> COLUMN_STATS_USAGE [ShowLikeOrWhere]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p><code>SHOW COLUMN_STATS_USAGE</code> 会输出 6 列,具体如下:</p><table><thead><tr><th>列名</th><th>说明</th></tr></thead><tbody><tr><td>Db_name</td><td>数据库名</td></tr><tr><td>Table_name</td><td>表名</td></tr><tr><td>Partition_name</td><td>分区名</td></tr><tr><td>Column_name</td><td>列名</td></tr><tr><td>Last_used_at</td><td>该列统计信息在最近一次查询优化中被用到的时间</td></tr><tr><td>Last_analyzed_at</td><td>该列统计信息最近一次被收集的时间</td></tr></tbody></table><p>在以下示例中,执行 <code>ANALYZE TABLE t PREDICATE COLUMNS;</code> 后,TiDB 将收集 <code>b</code>,<code>c</code>,<code>d</code> 列的统计信息,其中 <code>b</code> 列是 <code>PREDICATE COLUMN</code>,<code>c</code> 列和 <code>d</code> 列是索引列。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SET</span> <span class="hljs-keyword">GLOBAL</span> tidb_enable_column_tracking <span class="hljs-operator">=</span> <span class="hljs-keyword">ON</span>; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected (<span class="hljs-number">0.00</span> sec) <span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> t (a <span class="hljs-type">INT</span>, b <span class="hljs-type">INT</span>, c <span class="hljs-type">INT</span>, d <span class="hljs-type">INT</span>, INDEX idx_c_d(c, d)); Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected (<span class="hljs-number">0.00</span> sec) <span class="hljs-comment">-- 在此查询中优化器用到了 b 列的统计信息。</span> <span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> t <span class="hljs-keyword">WHERE</span> b <span class="hljs-operator">></span> <span class="hljs-number">1</span>; <span class="hljs-keyword">Empty</span> <span class="hljs-keyword">set</span> (<span class="hljs-number">0.00</span> sec) <span class="hljs-comment">-- 等待一段时间(100 * stats-lease)后,TiDB 将收集的 `PREDICATE COLUMNS` 写入 mysql.column_stats_usage。</span> <span class="hljs-comment">-- 指定 `last_used_at IS NOT NULL` 表示显示 TiDB 收集到的 `PREDICATE COLUMNS`。</span> <span class="hljs-keyword">SHOW</span> COLUMN_STATS_USAGE <span class="hljs-keyword">WHERE</span> db_name <span class="hljs-operator">=</span> <span class="hljs-string">'test'</span> <span class="hljs-keyword">AND</span> table_name <span class="hljs-operator">=</span> <span class="hljs-string">'t'</span> <span class="hljs-keyword">AND</span> last_used_at <span class="hljs-keyword">IS</span> <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span>; <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+-------------+---------------------+------------------+</span> <span class="hljs-operator">|</span> Db_name <span class="hljs-operator">|</span> Table_name <span class="hljs-operator">|</span> Partition_name <span class="hljs-operator">|</span> Column_name <span class="hljs-operator">|</span> Last_used_at <span class="hljs-operator">|</span> Last_analyzed_at <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+-------------+---------------------+------------------+</span> <span class="hljs-operator">|</span> test <span class="hljs-operator">|</span> t <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> b <span class="hljs-operator">|</span> <span class="hljs-number">2022</span><span class="hljs-number">-01</span><span class="hljs-number">-05</span> <span class="hljs-number">17</span>:<span class="hljs-number">21</span>:<span class="hljs-number">33</span> <span class="hljs-operator">|</span> <span class="hljs-keyword">NULL</span> <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+-------------+---------------------+------------------+</span> <span class="hljs-number">1</span> <span class="hljs-type">row</span> <span class="hljs-keyword">in</span> <span class="hljs-keyword">set</span> (<span class="hljs-number">0.00</span> sec) ANALYZE <span class="hljs-keyword">TABLE</span> t PREDICATE COLUMNS; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected, <span class="hljs-number">1</span> warning (<span class="hljs-number">0.03</span> sec) <span class="hljs-comment">-- 指定 `last_analyzed_at IS NOT NULL` 表示显示收集过统计信息的列。</span> <span class="hljs-keyword">SHOW</span> COLUMN_STATS_USAGE <span class="hljs-keyword">WHERE</span> db_name <span class="hljs-operator">=</span> <span class="hljs-string">'test'</span> <span class="hljs-keyword">AND</span> table_name <span class="hljs-operator">=</span> <span class="hljs-string">'t'</span> <span class="hljs-keyword">AND</span> last_analyzed_at <span class="hljs-keyword">IS</span> <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span>; <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+-------------+---------------------+---------------------+</span> <span class="hljs-operator">|</span> Db_name <span class="hljs-operator">|</span> Table_name <span class="hljs-operator">|</span> Partition_name <span class="hljs-operator">|</span> Column_name <span class="hljs-operator">|</span> Last_used_at <span class="hljs-operator">|</span> Last_analyzed_at <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+-------------+---------------------+---------------------+</span> <span class="hljs-operator">|</span> test <span class="hljs-operator">|</span> t <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> b <span class="hljs-operator">|</span> <span class="hljs-number">2022</span><span class="hljs-number">-01</span><span class="hljs-number">-05</span> <span class="hljs-number">17</span>:<span class="hljs-number">21</span>:<span class="hljs-number">33</span> <span class="hljs-operator">|</span> <span class="hljs-number">2022</span><span class="hljs-number">-01</span><span class="hljs-number">-05</span> <span class="hljs-number">17</span>:<span class="hljs-number">23</span>:<span class="hljs-number">06</span> <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> test <span class="hljs-operator">|</span> t <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> c <span class="hljs-operator">|</span> <span class="hljs-keyword">NULL</span> <span class="hljs-operator">|</span> <span class="hljs-number">2022</span><span class="hljs-number">-01</span><span class="hljs-number">-05</span> <span class="hljs-number">17</span>:<span class="hljs-number">23</span>:<span class="hljs-number">06</span> <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> test <span class="hljs-operator">|</span> t <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> d <span class="hljs-operator">|</span> <span class="hljs-keyword">NULL</span> <span class="hljs-operator">|</span> <span class="hljs-number">2022</span><span class="hljs-number">-01</span><span class="hljs-number">-05</span> <span class="hljs-number">17</span>:<span class="hljs-number">23</span>:<span class="hljs-number">06</span> <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+-------------+---------------------+---------------------+</span> <span class="hljs-number">3</span> <span class="hljs-keyword">rows</span> <span class="hljs-keyword">in</span> <span class="hljs-keyword">set</span> (<span class="hljs-number">0.00</span> sec) </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><h4 id="收集索引的统计信息" style="position:relative"><a href="#%E6%94%B6%E9%9B%86%E7%B4%A2%E5%BC%95%E7%9A%84%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF" aria-label="收集索引的统计信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>收集索引的统计信息</h4><p>如果要收集 TableName 中 IndexNameList 里所有索引的统计信息,请使用以下语法:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">ANALYZE <span class="hljs-keyword">TABLE</span> TableName INDEX [IndexNameList] [<span class="hljs-keyword">WITH</span> NUM BUCKETS<span class="hljs-operator">|</span>TOPN<span class="hljs-operator">|</span>CMSKETCH DEPTH<span class="hljs-operator">|</span>CMSKETCH WIDTH]<span class="hljs-operator">|</span>[<span class="hljs-keyword">WITH</span> NUM SAMPLES<span class="hljs-operator">|</span><span class="hljs-keyword">WITH</span> FLOATNUM SAMPLERATE]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>当 IndexNameList 为空时,该语法将收集 TableName 中所有索引的统计信息。</p><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardInfo MuiAlert-standard css-152gid5" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="InfoOutlinedIcon"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20, 12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10, 10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">注意</div><p>为了保证前后统计信息的一致性,当设置 <code>tidb_analyze_version=2</code> 时,该语句也会收集整个表的统计信息(包括所有列和所有索引的统计信息)而不限于索引的统计信息。</p></div></div></div><h4 id="收集分区的统计信息" style="position:relative"><a href="#%E6%94%B6%E9%9B%86%E5%88%86%E5%8C%BA%E7%9A%84%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF" aria-label="收集分区的统计信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>收集分区的统计信息</h4><ul><li><p>如果要收集 TableName 中所有的 PartitionNameList 中分区的统计信息,请使用以下语法:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">ANALYZE <span class="hljs-keyword">TABLE</span> TableName <span class="hljs-keyword">PARTITION</span> PartitionNameList [<span class="hljs-keyword">WITH</span> NUM BUCKETS<span class="hljs-operator">|</span>TOPN<span class="hljs-operator">|</span>CMSKETCH DEPTH<span class="hljs-operator">|</span>CMSKETCH WIDTH]<span class="hljs-operator">|</span>[<span class="hljs-keyword">WITH</span> NUM SAMPLES<span class="hljs-operator">|</span><span class="hljs-keyword">WITH</span> FLOATNUM SAMPLERATE]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre></li><li><p>如果要收集 TableName 中所有的 PartitionNameList 中分区的索引统计信息,请使用以下语法:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">ANALYZE <span class="hljs-keyword">TABLE</span> TableName <span class="hljs-keyword">PARTITION</span> PartitionNameList INDEX [IndexNameList] [<span class="hljs-keyword">WITH</span> NUM BUCKETS<span class="hljs-operator">|</span>TOPN<span class="hljs-operator">|</span>CMSKETCH DEPTH<span class="hljs-operator">|</span>CMSKETCH WIDTH]<span class="hljs-operator">|</span>[<span class="hljs-keyword">WITH</span> NUM SAMPLES<span class="hljs-operator">|</span><span class="hljs-keyword">WITH</span> FLOATNUM SAMPLERATE]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre></li><li><p>当收集分区的统计信息时,如果只<a href="/zh/tidb/stable/statistics#收集部分列的统计信息">收集部分列的统计信息</a>,请使用以下语法:</p><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardError MuiAlert-standard css-21rxh6" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ErrorOutlineIcon"><path d="M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">警告</div><p>收集 <code>PREDICATE COLUMNS</code> 的统计信息目前为实验特性,不建议在生产环境中使用。</p></div></div></div><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">ANALYZE <span class="hljs-keyword">TABLE</span> TableName <span class="hljs-keyword">PARTITION</span> PartitionNameList [COLUMNS ColumnNameList<span class="hljs-operator">|</span>PREDICATE COLUMNS<span class="hljs-operator">|</span><span class="hljs-keyword">ALL</span> COLUMNS] [<span class="hljs-keyword">WITH</span> NUM BUCKETS<span class="hljs-operator">|</span>TOPN<span class="hljs-operator">|</span>CMSKETCH DEPTH<span class="hljs-operator">|</span>CMSKETCH WIDTH]<span class="hljs-operator">|</span>[<span class="hljs-keyword">WITH</span> NUM SAMPLES<span class="hljs-operator">|</span><span class="hljs-keyword">WITH</span> FLOATNUM SAMPLERATE]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre></li></ul><h4 id="动态裁剪模式下的分区表统计信息" style="position:relative"><a href="#%E5%8A%A8%E6%80%81%E8%A3%81%E5%89%AA%E6%A8%A1%E5%BC%8F%E4%B8%8B%E7%9A%84%E5%88%86%E5%8C%BA%E8%A1%A8%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF" aria-label="动态裁剪模式下的分区表统计信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>动态裁剪模式下的分区表统计信息</h4><p>分区表在开启<a href="/zh/tidb/stable/partitioned-table#动态裁剪模式">动态裁剪模式</a>的情况下,TiDB 将收集表级别的汇总统计信息,以下称 GlobalStats。 目前 GlobalStats 由分区统计信息合并汇总得到。在动态裁剪模式开启的情况下,任一分区上的统计信息更新都会触发 GlobalStats 的更新。</p><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardInfo MuiAlert-standard css-152gid5" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="InfoOutlinedIcon"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20, 12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10, 10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">注意</div><ul><li><p>当触发 GlobalStats 更新时,如果 <a href="/zh/tidb/stable/system-variables#tidb_skip_missing_partition_stats-从-v730-版本开始引入"><code>tidb_skip_missing_partition_stats</code></a> 关闭:</p><ul><li>若某些分区上缺少统计信息(比如新增的未 analyze 过的分区),会停止生成 GlobalStats,并通过 warning 信息提示用户缺少分区的统计信息。</li><li>若某些列的统计信息合并过程中,缺少某些分区在该列上的统计信息(在不同分区上 analyze 时指定了不同的列),会停止生成 GlobalStats,并通过 warning 信息提示用户缺少列在分区上的统计信息。</li></ul></li><li><p>当触发 GlobalStats 更新时,如果 <a href="/zh/tidb/stable/system-variables#tidb_skip_missing_partition_stats-从-v730-版本开始引入"><code>tidb_skip_missing_partition_stats</code></a> 开启:</p><p> 如果某些分区缺失全部或者部分列的统计信息,TiDB 生成 GlobalStats 时会跳过缺失的分区统计信息,不影响 GlobalStats 生成。</p></li><li><p>在动态裁剪模式开启的情况下,分区和表的 ANALYZE 配置需要保持一致,因此 ANALYZE TABLE TableName PARTITION PartitionNameList 命令后指定的 COLUMNS 配置和 WITH 后指定的 OPTIONS 配置将被忽略,并会通过 warning 信息提示用户。</p></li></ul></div></div></div><h3 id="自动更新" style="position:relative"><a href="#%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0" aria-label="自动更新 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>自动更新</h3><p>在发生增加,删除以及修改语句时,TiDB 会自动更新表的总行数以及修改的行数。这些信息会定期持久化下来,更新的周期为 20 * <a href="/zh/tidb/stable/tidb-configuration-file#stats-lease"><code>stats-lease</code></a>。<code>stats-lease</code> 配置项的默认值是 3s,如果将其指定为 0,那么统计信息将不会自动更新。</p><h4 id="相关系统变量" style="position:relative"><a href="#%E7%9B%B8%E5%85%B3%E7%B3%BB%E7%BB%9F%E5%8F%98%E9%87%8F" aria-label="相关系统变量 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>相关系统变量</h4><table><thead><tr><th>系统变量名</th><th>默认值</th><th>功能</th></tr></thead><tbody><tr><td><a href="/zh/tidb/stable/system-variables#tidb_auto_analyze_ratio"><code>tidb_auto_analyze_ratio</code></a></td><td>0.5</td><td>自动更新阈值</td></tr><tr><td><a href="/zh/tidb/stable/system-variables#tidb_auto_analyze_start_time"><code>tidb_auto_analyze_start_time</code></a></td><td><code>00:00 +0000</code></td><td>一天中能够进行自动更新的开始时间</td></tr><tr><td><a href="/zh/tidb/stable/system-variables#tidb_auto_analyze_end_time"><code>tidb_auto_analyze_end_time</code></a></td><td><code>23:59 +0000</code></td><td>一天中能够进行自动更新的结束时间</td></tr><tr><td><a href="/zh/tidb/stable/system-variables#tidb_auto_analyze_partition_batch_size-从-v640-版本开始引入"><code>tidb_auto_analyze_partition_batch_size</code></a></td><td><code>1</code></td><td>TiDB 自动 analyze 分区表(即自动更新分区表的统计信息)时,每次同时 analyze 分区的个数</td></tr></tbody></table><p>当某个表 <code>tbl</code> 的修改行数与总行数的比值大于 <code>tidb_auto_analyze_ratio</code>,并且当前时间在 <code>tidb_auto_analyze_start_time</code> 和 <code>tidb_auto_analyze_end_time</code> 之间时,TiDB 会在后台执行 <code>ANALYZE TABLE tbl</code> 语句自动更新这个表的统计信息。</p><p>为了避免小表因为少量数据修改而频繁触发自动更新,当表的行数小于 1000 时,TiDB 不会触发对此表的自动更新。你可以通过 <code>SHOW STATS_META</code> 来查看表的行数情况。</p><h4 id="关闭自动更新" style="position:relative"><a href="#%E5%85%B3%E9%97%AD%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0" aria-label="关闭自动更新 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>关闭自动更新</h4><p>如果发现自动更新统计信息消耗过多的资源,影响在线业务,可以通过系统变量 <a href="/zh/tidb/stable/system-variables#tidb_enable_auto_analyze-从-v610-版本开始引入"><code>tidb_enable_auto_analyze</code></a> 关闭自动更新。</p><h4 id="终止后台的-analyze-任务" style="position:relative"><a href="#%E7%BB%88%E6%AD%A2%E5%90%8E%E5%8F%B0%E7%9A%84-analyze-%E4%BB%BB%E5%8A%A1" aria-label="终止后台的 analyze 任务 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>终止后台的 <code>ANALYZE</code> 任务</h4><p>从 TiDB v6.0 起,TiDB 支持通过 <code>KILL</code> 语句终止正在后台运行的 <code>ANALYZE</code> 任务。如果发现正在后台运行的 <code>ANALYZE</code> 任务消耗大量资源影响业务,你可以通过以下步骤终止该 <code>ANALYZE</code> 任务:</p><ol><li><p>执行以下 SQL 语句:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SHOW</span> ANALYZE STATUS </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>查看 <code>instance</code> 列和 <code>process_id</code> 列获得正在执行后台 <code>ANALYZE</code> 任务的 TiDB 实例地址和任务 <code>ID</code>。</p></li><li><p>终止正在后台运行的 <code>ANALYZE</code> 任务。</p><ul><li>如果 <a href="/zh/tidb/stable/tidb-configuration-file#enable-global-kill-从-v610-版本开始引入"><code>enable-global-kill</code></a> 的值为 <code>true</code> (默认为 <code>true</code>),你可以直接执行 <code>KILL TIDB ${id};</code> 语句。其中,${id} 为上一步中查询得到的后台 <code>ANALYZE</code> 任务的 <code>ID</code>。</li><li>如果 <code>enable-global-kill</code> 的值为 <code>false</code>,你需要先使用客户端连接到执行后台 <code>ANALYZE</code> 任务的 TiDB 实例,然后再执行 <code>KILL TIDB ${id};</code> 语句。如果使用客户端连接到其他 TiDB 实例,或者客户端和 TiDB 中间有代理,<code>KILL</code> 语句不能终止后台的 <code>ANALYZE</code> 任务。</li></ul></li></ol><p>关于 <code>KILL</code> 语句的更多信息,请参考 <a href="/zh/tidb/stable/sql-statement-kill"><code>KILL [TIDB]</code></a>。</p><h3 id="控制-analyze-并发度" style="position:relative"><a href="#%E6%8E%A7%E5%88%B6-analyze-%E5%B9%B6%E5%8F%91%E5%BA%A6" aria-label="控制 analyze 并发度 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>控制 ANALYZE 并发度</h3><p>执行 ANALYZE 语句的时候,你可以通过一些系统变量来调整并发度,以控制对系统的影响。</p><p>相关系统变量的关系如下图所示:</p><p><img src="https://download.pingcap.com/images/docs-cn/analyze_concurrency.png" alt="analyze_concurrency"/></p><p><code>tidb_build_stats_concurrency</code>、<code>tidb_build_sampling_stats_concurrency</code> 和 <code>tidb_analyze_partition_concurrency</code> 为上下游关系。实际的总并发为:<code>tidb_build_stats_concurrency</code>* (<code>tidb_build_sampling_stats_concurrency</code> + <code>tidb_analyze_partition_concurrency</code>) 。所以在变更这些参数的时候,需要同时考虑这三个参数的值。建议按 <code>tidb_analyze_partition_concurrency</code>、<code>tidb_build_sampling_stats_concurrency</code>、<code>tidb_build_stats_concurrency</code> 的顺序逐个调节,并观察对系统的影响。这三个参数的值越大,对系统的资源开销就越大。</p><h4 id="tidb_build_stats_concurrency" style="position:relative"><a href="#tidb_build_stats_concurrency" aria-label="tidb_build_stats_concurrency permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a><code>tidb_build_stats_concurrency</code></h4><p><code>ANALYZE</code> 在执行时会被切分成一个个小任务,每个任务只负责某一个列或者索引的统计信息收集。<a href="/zh/tidb/stable/system-variables#tidb_build_stats_concurrency"><code>tidb_build_stats_concurrency</code></a> 用于控制可以同时执行的小任务的数量,其默认值是 <code>2</code>。TiDB v7.4.0 及其之前版本默认值为 <code>4</code>。</p><h4 id="tidb_build_sampling_stats_concurrency" style="position:relative"><a href="#tidb_build_sampling_stats_concurrency" aria-label="tidb_build_sampling_stats_concurrency permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a><code>tidb_build_sampling_stats_concurrency</code></h4><p>在执行 <code>ANALYZE</code> 普通列任务的时候,<a href="/zh/tidb/stable/system-variables#tidb_build_sampling_stats_concurrency-从-v750-版本开始引入"><code>tidb_build_sampling_stats_concurrency</code></a> 可以用于控制执行采样任务的并发数量,其默认值是 <code>2</code>。</p><h4 id="tidb_analyze_partition_concurrency" style="position:relative"><a href="#tidb_analyze_partition_concurrency" aria-label="tidb_analyze_partition_concurrency permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a><code>tidb_analyze_partition_concurrency</code></h4><p>在执行 <code>ANALYZE</code> 的时候,<a href="/zh/tidb/stable/system-variables#tidb_analyze_partition_concurrency"><code>tidb_analyze_partition_concurrency</code></a> 可以用于控制对分区表统计信息进行读写的并发度,其默认值是 <code>2</code>。TiDB v7.4.0 及其之前版本默认值为 <code>1</code>。</p><h4 id="tidb_distsql_scan_concurrency" style="position:relative"><a href="#tidb_distsql_scan_concurrency" aria-label="tidb_distsql_scan_concurrency permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a><code>tidb_distsql_scan_concurrency</code></h4><p>在执行分析普通列任务的时候,<a href="/zh/tidb/stable/system-variables#tidb_distsql_scan_concurrency"><code>tidb_distsql_scan_concurrency</code></a> 可以用于控制一次读取的 Region 数量,其默认值是 15。修改该变量值会影响查询性能,请谨慎调整。</p><h4 id="tidb_index_serial_scan_concurrency" style="position:relative"><a href="#tidb_index_serial_scan_concurrency" aria-label="tidb_index_serial_scan_concurrency permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a><code>tidb_index_serial_scan_concurrency</code></h4><p>在执行分析索引列任务的时候,<a href="/zh/tidb/stable/system-variables#tidb_index_serial_scan_concurrency"><code>tidb_index_serial_scan_concurrency</code></a> 可以用于控制一次读取的 Region 数量,其默认值是 1。修改该变量值会影响查询性能,请谨慎调整。</p><h3 id="analyze-配置持久化" style="position:relative"><a href="#analyze-%E9%85%8D%E7%BD%AE%E6%8C%81%E4%B9%85%E5%8C%96" aria-label="analyze 配置持久化 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>ANALYZE 配置持久化</h3><p>从 v5.4.0 起,TiDB 支持 <code>ANALYZE</code> 配置持久化功能,方便后续收集统计信息时沿用已有配置项。</p><p>TiDB 支持持久化的配置项包括:</p><table><thead><tr><th>配置项</th><th>对应的 ANALYZE 语法</th></tr></thead><tbody><tr><td>直方图桶数</td><td>WITH NUM BUCKETS</td></tr><tr><td>TopN 个数</td><td>WITH NUM TOPN</td></tr><tr><td>采样数</td><td>WITH NUM SAMPLES</td></tr><tr><td>采样率</td><td>WITH FLOATNUM SAMPLERATE</td></tr><tr><td>ANALYZE 的列的类型</td><td>AnalyzeColumnOption ::= ( 'ALL COLUMNS' <!-- -->|<!-- --> 'PREDICATE COLUMNS' <!-- -->|<!-- --> 'COLUMNS' ColumnNameList )</td></tr><tr><td>ANALYZE 的列</td><td>ColumnNameList ::= Identifier ( ',' Identifier )*</td></tr></tbody></table><h4 id="开启-analyze-配置持久化功能" style="position:relative"><a href="#%E5%BC%80%E5%90%AF-analyze-%E9%85%8D%E7%BD%AE%E6%8C%81%E4%B9%85%E5%8C%96%E5%8A%9F%E8%83%BD" aria-label="开启 analyze 配置持久化功能 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>开启 ANALYZE 配置持久化功能</h4><p><code>ANALYZE</code> 配置持久化功能默认开启(系统变量 <code>tidb_analyze_version</code> 为默认值 <code>2</code>,<code>tidb_persist_analyze_options</code> 为默认值 <code>ON</code>),用于记录手动执行 <code>ANALYZE</code> 语句时指定的持久化配置项。记录后,当 TiDB 下一次自动更新统计信息或者你手动收集统计信息但未指定配置项时,TiDB 会按照记录的配置项收集统计信息。</p><p>要查询用于自动分析操作的特定表上持久化的配置,可以使用以下 SQL 语句:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SELECT</span> sample_num, sample_rate, buckets, topn, column_choice, column_ids <span class="hljs-keyword">FROM</span> mysql.analyze_options opt <span class="hljs-keyword">JOIN</span> information_schema.tables tbl <span class="hljs-keyword">ON</span> opt.table_id <span class="hljs-operator">=</span> tbl.tidb_table_id <span class="hljs-keyword">WHERE</span> tbl.table_schema <span class="hljs-operator">=</span> <span class="hljs-string">'{db_name}'</span> <span class="hljs-keyword">AND</span> tbl.table_name <span class="hljs-operator">=</span> <span class="hljs-string">'{table_name}'</span>; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>TiDB 将使用最新 <code>ANALYZE</code> 语句指定的配置覆盖先前记录的持久配置。例如,如果你运行 <code>ANALYZE TABLE t WITH 200 TOPN;</code> ,它将在 <code>ANALYZE</code> 语句中设置前 200 个值。随后,执行 <code>ANALYZE TABLE t WITH 0.1 SAMPLERATE;</code> 将为自动 <code>ANALYZE</code> 语句同时设置前 200 个值和 0.1 的采样率,类似于 <code>ANALYZE TABLE t WITH 200 TOPN, 0.1 SAMPLERATE;</code> 。</p><h4 id="关闭-analyze-配置持久化功能" style="position:relative"><a href="#%E5%85%B3%E9%97%AD-analyze-%E9%85%8D%E7%BD%AE%E6%8C%81%E4%B9%85%E5%8C%96%E5%8A%9F%E8%83%BD" aria-label="关闭 analyze 配置持久化功能 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>关闭 ANALYZE 配置持久化功能</h4><p>要关闭 <code>ANALYZE</code> 配置持久化功能,请设置系统变量 <code>tidb_persist_analyze_options</code> 为 <code>OFF</code>。由于 <code>ANALYZE</code> 配置持久化功能在 <code>tidb_analyze_version = 1</code> 的情况下不适用,因此设置 <code>tidb_analyze_version = 1</code> 同样会达到关闭配置持久化的效果。</p><p>关闭 <code>ANALYZE</code> 配置持久化功能后,已持久化的配置记录不会被清除。因此,当再次开启该功能时,TiDB 会继续使用之前记录的持久化配置收集统计信息。</p><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardInfo MuiAlert-standard css-152gid5" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="InfoOutlinedIcon"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20, 12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10, 10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">注意</div><p>当再次开启 <code>ANALYZE</code> 配置持久化功能时,如果之前记录的持久化配置项已经不适用当前的数据,请手动执行 <code>ANALYZE</code> 语句并指定新的持久化配置项。</p></div></div></div><h4 id="分区表的-analyze-配置持久化功能" style="position:relative"><a href="#%E5%88%86%E5%8C%BA%E8%A1%A8%E7%9A%84-analyze-%E9%85%8D%E7%BD%AE%E6%8C%81%E4%B9%85%E5%8C%96%E5%8A%9F%E8%83%BD" aria-label="分区表的 analyze 配置持久化功能 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>分区表的 ANALYZE 配置持久化功能</h4><p>在静态裁剪模式下 ANALYZE 分区表时,配置持久化遵守:</p><ul><li>ANALYZE TABLE 时会持久化表级别的配置和实际被 ANALYZE 的所有分区的配置</li><li>分区的统计信息会继承使用表级别的持久化配置</li><li>ANALYZE TABLE ... PARTITION ... WITH ... 所指定的分区配置只持久化到分区级别,不会影响表级别的持久化配置</li><li>当 ANALYZE 语句指定了配置,且同时存在持久化配置时,按照语句 > 分区 > 表的优先级继承和重写配置信息</li></ul><p>在<a href="/zh/tidb/stable/partitioned-table#动态裁剪模式">动态裁剪模式</a>下 ANALYZE 分区表时,配置持久化遵守:</p><ul><li>ANALYZE TABLE 时只持久化表级别的配置</li><li>分区的统计信息会继承使用表级别的持久化配置</li><li>GlobalStats 会使用表级别的持久化配置</li><li>ANALYZE TABLE ... PARTITION ... WITH ... 所指定的分区配置会被忽略,且不会被持久化</li></ul><h3 id="统计信息收集的内存限制" style="position:relative"><a href="#%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%E6%94%B6%E9%9B%86%E7%9A%84%E5%86%85%E5%AD%98%E9%99%90%E5%88%B6" aria-label="统计信息收集的内存限制 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>统计信息收集的内存限制</h3><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardError MuiAlert-standard css-21rxh6" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ErrorOutlineIcon"><path d="M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">警告</div><p>目前限制 ANALYZE 的内存使用量为实验特性,在生产环境中使用时可能存在内存统计有误差的情况。</p></div></div></div><p>TiDB 从 v6.1.0 开始引入了统计信息收集的内存限制,你可以通过 <a href="/zh/tidb/stable/system-variables#tidb_mem_quota_analyze-从-v610-版本开始引入"><code>tidb_mem_quota_analyze</code></a> 变量来控制 TiDB 更新统计信息时的最大总内存占用。</p><p>要合理地配置 <code>tidb_mem_quota_analyze</code> 值,你需要考虑集群的数据。在使用默认采样率的情况下,主要考虑列的数量、列上的值的大小,以及 TiDB 的内存配置。你可参考以下建议来配置变量的最大值和最小值:</p><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardInfo MuiAlert-standard css-152gid5" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="InfoOutlinedIcon"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20, 12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10, 10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">注意</div><p>以下配置建议仅供参考,实际配置需要在真实场景中测试确定。</p></div></div></div><ul><li>最小值:需要大于 TiDB 从集群上列最多的表收集统计信息时使用的最大内存。一个粗略的参考信息是,在测试集上,20 列的表在默认配置下,统计信息收集的最大内存使用约为 800 MiB;160 列的表在默认配置下,统计信息收集的最大内存使用约为 5 GiB。</li><li>最大值:需要小于集群在不进行统计信息收集时的内存空余量。</li></ul><h3 id="查看-analyze-状态" style="position:relative"><a href="#%E6%9F%A5%E7%9C%8B-analyze-%E7%8A%B6%E6%80%81" aria-label="查看 analyze 状态 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>查看 ANALYZE 状态</h3><p>在执行 <code>ANALYZE</code> 时,可以通过 SQL 语句来查看当前 <code>ANALYZE</code> 的状态。</p><p>语法如下:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SHOW</span> ANALYZE STATUS [ShowLikeOrWhere]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>该语句会输出 <code>ANALYZE</code> 的状态,可以通过使用 <code>ShowLikeOrWhere</code> 来筛选需要的信息。</p><p>目前 <code>SHOW ANALYZE STATUS</code> 会输出 11 列,具体如下:</p><table><thead><tr><th>列名</th><th>说明</th></tr></thead><tbody><tr><td>table_schema</td><td>数据库名</td></tr><tr><td>table_name</td><td>表名</td></tr><tr><td>partition_name</td><td>分区名</td></tr><tr><td>job_info</td><td>任务具体信息。如果分析索引,该信息会包含索引名。当 <code>tidb_analyze_version =2</code> 时,该信息会包含采样率等配置项。</td></tr><tr><td>processed_rows</td><td>已经分析的行数</td></tr><tr><td>start_time</td><td>任务开始执行的时间</td></tr><tr><td>end_time</td><td>任务结束执行的时间</td></tr><tr><td>state</td><td>任务状态,包括 pending(等待)、running(正在执行)、finished(执行成功)和 failed(执行失败)</td></tr><tr><td>fail_reason</td><td>任务失败的原因。如果执行成功则为 <code>NULL</code>。</td></tr><tr><td>instance</td><td>执行任务的 TiDB 实例</td></tr><tr><td>process_id</td><td>执行任务的 process ID</td></tr></tbody></table><p>从 TiDB v6.1.0 起,执行 <code>SHOW ANALYZE STATUS</code> 语句将显示集群级别的任务,且 TiDB 重启后仍能看到重启之前的任务记录。在 TiDB v6.1.0 之前,执行 <code>SHOW ANALYZE STATUS</code> 语句仅显示实例级别的任务,且 TiDB 重启后任务记录会被清空。</p><p><code>SHOW ANALYZE STATUS</code> 仅显示最近的任务记录。从 TiDB v6.1 起,你可以通过系统表 <code>mysql.analyze_jobs</code> 查看过去 7 天内的历史记录。</p><p>当设置了 <a href="/zh/tidb/stable/system-variables#tidb_mem_quota_analyze-从-v610-版本开始引入"><code>tidb_mem_quota_analyze</code></a> 且 TiDB 后台的统计信息自动更新任务的内存占用超过了这个阈值时,自动更新任务会重试。失败的任务和重试的任务都可以在 <code>SHOW ANALYZE STATUS</code> 的结果中查看。</p><p>当 <a href="/zh/tidb/stable/system-variables#tidb_max_auto_analyze_time-从-v610-版本开始引入"><code>tidb_max_auto_analyze_time</code></a> 大于 0 时,如果后台统计信息自动更新任务的执行时间超过这个阈值,该任务会被终止。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">mysql<span class="hljs-operator">></span> <span class="hljs-keyword">SHOW</span> ANALYZE STATUS [ShowLikeOrWhere]; <span class="hljs-operator">+</span><span class="hljs-comment">--------------+------------+----------------+-------------------------------------------------------------------------------------------+----------------+---------------------+---------------------+----------+-------------------------------------------------------------------------------|</span> <span class="hljs-operator">|</span> Table_schema <span class="hljs-operator">|</span> Table_name <span class="hljs-operator">|</span> Partition_name <span class="hljs-operator">|</span> Job_info <span class="hljs-operator">|</span> Processed_rows <span class="hljs-operator">|</span> Start_time <span class="hljs-operator">|</span> End_time <span class="hljs-operator">|</span> State <span class="hljs-operator">|</span> Fail_reason <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">--------------+------------+----------------+-------------------------------------------------------------------------------------------+----------------+---------------------+---------------------+----------+-------------------------------------------------------------------------------|</span> <span class="hljs-operator">|</span> test <span class="hljs-operator">|</span> sbtest1 <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> retry auto analyze <span class="hljs-keyword">table</span> <span class="hljs-keyword">all</span> columns <span class="hljs-keyword">with</span> <span class="hljs-number">100</span> topn, <span class="hljs-number">0.055</span> samplerate <span class="hljs-operator">|</span> <span class="hljs-number">2000000</span> <span class="hljs-operator">|</span> <span class="hljs-number">2022</span><span class="hljs-number">-05</span><span class="hljs-number">-07</span> <span class="hljs-number">16</span>:<span class="hljs-number">41</span>:<span class="hljs-number">09</span> <span class="hljs-operator">|</span> <span class="hljs-number">2022</span><span class="hljs-number">-05</span><span class="hljs-number">-07</span> <span class="hljs-number">16</span>:<span class="hljs-number">41</span>:<span class="hljs-number">20</span> <span class="hljs-operator">|</span> finished <span class="hljs-operator">|</span> <span class="hljs-keyword">NULL</span> <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> test <span class="hljs-operator">|</span> sbtest1 <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> auto analyze <span class="hljs-keyword">table</span> <span class="hljs-keyword">all</span> columns <span class="hljs-keyword">with</span> <span class="hljs-number">100</span> topn, <span class="hljs-number">0.5</span> samplerate <span class="hljs-operator">|</span> <span class="hljs-number">0</span> <span class="hljs-operator">|</span> <span class="hljs-number">2022</span><span class="hljs-number">-05</span><span class="hljs-number">-07</span> <span class="hljs-number">16</span>:<span class="hljs-number">40</span>:<span class="hljs-number">50</span> <span class="hljs-operator">|</span> <span class="hljs-number">2022</span><span class="hljs-number">-05</span><span class="hljs-number">-07</span> <span class="hljs-number">16</span>:<span class="hljs-number">41</span>:<span class="hljs-number">09</span> <span class="hljs-operator">|</span> failed <span class="hljs-operator">|</span> analyze panic due <span class="hljs-keyword">to</span> memory quota exceeds, please try <span class="hljs-keyword">with</span> smaller samplerate <span class="hljs-operator">|</span> </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><h2 id="统计信息的查看" style="position:relative"><a href="#%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%E7%9A%84%E6%9F%A5%E7%9C%8B" aria-label="统计信息的查看 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>统计信息的查看</h2><p>你可以通过一些语句来查看统计信息的状态。</p><h3 id="表的元信息" style="position:relative"><a href="#%E8%A1%A8%E7%9A%84%E5%85%83%E4%BF%A1%E6%81%AF" aria-label="表的元信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>表的元信息</h3><p>你可以通过 <code>SHOW STATS_META</code> 来查看表的总行数以及修改的行数等信息。</p><p>语法如下:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SHOW</span> STATS_META [ShowLikeOrWhere]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>其中,<code>ShowLikeOrWhereOpt</code> 部分的语法图为:</p><p><img src="https://download.pingcap.com/images/docs-cn/sqlgram/ShowLikeOrWhereOpt.png" alt="ShowLikeOrWhereOpt"/></p><p>目前 <code>SHOW STATS_META</code> 会输出 6 列,具体如下:</p><table><thead><tr><th>列名</th><th>说明</th></tr></thead><tbody><tr><td>db_name</td><td>数据库名</td></tr><tr><td>table_name</td><td>表名</td></tr><tr><td>partition_name</td><td>分区名</td></tr><tr><td>update_time</td><td>更新时间</td></tr><tr><td>modify_count</td><td>修改的行数</td></tr><tr><td>row_count</td><td>总行数</td></tr></tbody></table><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardInfo MuiAlert-standard css-152gid5" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="InfoOutlinedIcon"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20, 12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10, 10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">注意</div><p>在 TiDB 根据 DML 语句自动更新总行数以及修改的行数时,<code>update_time</code> 也会被更新,因此并不能认为 <code>update_time</code> 是最近一次发生 Analyze 的时间。</p></div></div></div><h3 id="表的健康度信息" style="position:relative"><a href="#%E8%A1%A8%E7%9A%84%E5%81%A5%E5%BA%B7%E5%BA%A6%E4%BF%A1%E6%81%AF" aria-label="表的健康度信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>表的健康度信息</h3><p>通过 <code>SHOW STATS_HEALTHY</code> 可以查看表的统计信息健康度,并粗略估计表上统计信息的准确度。当 <code>modify_count</code> >= <code>row_count</code> 时,健康度为 0;当 <code>modify_count</code> < <code>row_count</code> 时,健康度为 (1 - <code>modify_count</code>/<code>row_count</code>) * 100。</p><p>语法如下:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SHOW</span> STATS_HEALTHY [ShowLikeOrWhere]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p><code>SHOW STATS_HEALTHY</code> 的语法图为:</p><p><img src="https://download.pingcap.com/images/docs-cn/sqlgram/ShowStatsHealthy.png" alt="ShowStatsHealthy"/></p><p>目前,<code>SHOW STATS_HEALTHY</code> 会输出 4 列,具体如下:</p><table><thead><tr><th align="left">列名</th><th align="left">说明</th></tr></thead><tbody><tr><td align="left">db_name</td><td align="left">数据库名</td></tr><tr><td align="left">table_name</td><td align="left">表名</td></tr><tr><td align="left">partition_name</td><td align="left">分区名</td></tr><tr><td align="left">healthy</td><td align="left">健康度</td></tr></tbody></table><h3 id="列的元信息" style="position:relative"><a href="#%E5%88%97%E7%9A%84%E5%85%83%E4%BF%A1%E6%81%AF" aria-label="列的元信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>列的元信息</h3><p>你可以通过 <code>SHOW STATS_HISTOGRAMS</code> 来查看列的不同值数量以及 NULL 数量等信息。</p><p>语法如下:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SHOW</span> STATS_HISTOGRAMS [ShowLikeOrWhere]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>该语句会输出所有列的不同值数量以及 NULL 数量等信息,你可以通过 ShowLikeOrWhere 来筛选需要的信息。</p><p>目前 <code>SHOW STATS_HISTOGRAMS</code> 会输出 10 列,具体如下:</p><table><thead><tr><th>列名</th><th>说明</th></tr></thead><tbody><tr><td>db_name</td><td>数据库名</td></tr><tr><td>table_name</td><td>表名</td></tr><tr><td>partition_name</td><td>分区名</td></tr><tr><td>column_name</td><td>根据 is_index 来变化:is_index 为 0 时是列名,为 1 时是索引名</td></tr><tr><td>is_index</td><td>是否是索引列</td></tr><tr><td>update_time</td><td>更新时间</td></tr><tr><td>distinct_count</td><td>不同值数量</td></tr><tr><td>null_count</td><td>NULL 的数量</td></tr><tr><td>avg_col_size</td><td>列平均长度</td></tr><tr><td>correlation</td><td>该列与整型主键的皮尔逊系数,表示两列之间的关联程度</td></tr></tbody></table><h3 id="直方图桶的信息" style="position:relative"><a href="#%E7%9B%B4%E6%96%B9%E5%9B%BE%E6%A1%B6%E7%9A%84%E4%BF%A1%E6%81%AF" aria-label="直方图桶的信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>直方图桶的信息</h3><p>你可以通过 <code>SHOW STATS_BUCKETS</code> 来查看直方图每个桶的信息。</p><p>语法如下:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SHOW</span> STATS_BUCKETS [ShowLikeOrWhere]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>语法图:</p><p><strong>SHOW STATS_BUCKETS:</strong></p><p><img src="https://download.pingcap.com/images/docs-cn/sqlgram/SHOW_STATS_BUCKETS.png" alt="SHOW STATS_BUCKETS"/></p><p>该语句会输出所有桶的信息,你可以通过 ShowLikeOrWhere 来筛选需要的信息。</p><p>目前 <code>SHOW STATS_BUCKETS</code> 会输出 11 列,具体如下:</p><table><thead><tr><th>列名</th><th>说明</th></tr></thead><tbody><tr><td>db_name</td><td>数据库名</td></tr><tr><td>table_name</td><td>表名</td></tr><tr><td>partition_name</td><td>分区名</td></tr><tr><td>column_name</td><td>根据 is_index 来变化:is_index 为 0 时是列名,为 1 时是索引名</td></tr><tr><td>is_index</td><td>是否是索引列</td></tr><tr><td>bucket_id</td><td>桶的编号</td></tr><tr><td>count</td><td>所有落在这个桶及之前桶中值的数量</td></tr><tr><td>repeats</td><td>最大值出现的次数</td></tr><tr><td>lower_bound</td><td>最小值</td></tr><tr><td>upper_bound</td><td>最大值</td></tr><tr><td>ndv</td><td>当前桶内不同值的个数。当 <code>tidb_analyze_version</code> = 1 时,该值恒为 0,没有实际意义。</td></tr></tbody></table><h3 id="top-n-信息" style="position:relative"><a href="#top-n-%E4%BF%A1%E6%81%AF" aria-label="top n 信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>Top-N 信息</h3><p>你可以通过 <code>SHOW STATS_TOPN</code> 来查看当前 TiDB 中收集的 Top-N 值的信息。</p><p>语法如下:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">SHOW</span> STATS_TOPN [ShowLikeOrWhere]; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>目前 <code>SHOW STATS_TOPN</code> 会输出 7 列,具体如下:</p><table><thead><tr><th>列名</th><th>说明</th></tr></thead><tbody><tr><td>db_name</td><td>数据库名</td></tr><tr><td>table_name</td><td>表名</td></tr><tr><td>partition_name</td><td>分区名</td></tr><tr><td>column_name</td><td>根据 is_index 来变化:is_index 为 0 时是列名,为 1 时是索引名</td></tr><tr><td>is_index</td><td>是否是索引列</td></tr><tr><td>value</td><td>该列的值</td></tr><tr><td>count</td><td>该值出现的次数</td></tr></tbody></table><h2 id="删除统计信息" style="position:relative"><a href="#%E5%88%A0%E9%99%A4%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF" aria-label="删除统计信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>删除统计信息</h2><p>可以通过执行 <code>DROP STATS</code> 语句来删除统计信息。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">DROP</span> STATS TableName; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>该语句会删除 TableName 中所有的统计信息,如果是分区表,包括所有分区的统计信息和分区动态裁剪模式下生成的 GlobalStats。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">DROP</span> STATS TableName <span class="hljs-keyword">PARTITION</span> PartitionNameList; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>该语句只删除 PartitionNameList 中对应的分区的统计信息。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia"><span class="hljs-keyword">DROP</span> STATS TableName <span class="hljs-keyword">GLOBAL</span>; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>该语句只删除该表在分区动态裁剪模式下生成的 GlobalStats。</p><h2 id="统计信息的加载" style="position:relative"><a href="#%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%E7%9A%84%E5%8A%A0%E8%BD%BD" aria-label="统计信息的加载 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>统计信息的加载</h2><p>默认情况下,列的统计信息占用空间大小不同,TiDB 对统计信息的加载方式也会不同。</p><ul><li>对于 count、distinctCount、nullCount 等占用空间较小的统计信息,只要有数据更新,TiDB 就会自动将对应的统计信息加载进内存供 SQL 优化阶段使用。</li><li>对于直方图、TopN、CMSketch 等占用空间较大的统计信息,为了确保 SQL 执行的性能,TiDB 会按需进行异步加载。例如,对于直方图,只有当某条 SQL 语句的优化阶段使用到了某列的直方图统计信息时,TiDB 才会将该列的直方图信息加载到内存。按需异步加载的优势是统计信息加载不会影响到 SQL 执行的性能,但在 SQL 优化时有可能使用不完整的统计信息。</li></ul><p>从 v5.4.0 开始,TiDB 引入了统计信息同步加载的特性,支持执行当前 SQL 语句时将直方图、TopN、CMSketch 等占用空间较大的统计信息同步加载到内存,提高该 SQL 语句优化时统计信息的完整性。</p><p>要开启该特性,请将系统变量 <a href="/zh/tidb/stable/system-variables#tidb_stats_load_sync_wait-从-v540-版本开始引入"><code>tidb_stats_load_sync_wait</code></a> 的值设置为 SQL 优化等待加载列的完整统计信息的超时时间(单位为毫秒)。该变量默认值为 100,代表开启统计信息同步加载。</p><p>开启该特性后,你可以进一步配置该特性:</p><ul><li>通过修改系统变量 <a href="/zh/tidb/stable/system-variables#tidb_stats_load_pseudo_timeout-从-v540-版本开始引入"><code>tidb_stats_load_pseudo_timeout</code></a> 的值控制 SQL 优化等待超时后的行为。该变量默认值为 <code>ON</code>,代表超时后 SQL 优化过程不会使用任何列上的直方图、TopN 或 CMSketch。当设置该变量为 <code>OFF</code> 时,代表超时后 SQL 执行失败。</li><li>通过修改 TiDB 配置项 <a href="/zh/tidb/stable/tidb-configuration-file#stats-load-concurrency-从-v540-版本开始引入"><code>stats-load-concurrency</code></a> 的值控制统计信息同步加载可以并发处理的最大列数。该配置项的默认值为 <code>5</code>。</li><li>通过修改 TiDB 配置项 <a href="/zh/tidb/stable/tidb-configuration-file#stats-load-queue-size-从-v540-版本开始引入"><code>stats-load-queue-size</code></a> 的值设置统计信息同步加载最多可以缓存多少列的请求。该配置项的默认值为 <code>1000</code>。</li></ul><p>在 TiDB 启动阶段,初始统计信息加载完成之前执行的 SQL 可能有不合理的执行计划,从而影响性能。为了避免这种情况,从 v7.1.0 开始,TiDB 引入了配置项 <a href="/zh/tidb/stable/tidb-configuration-file#force-init-stats-从-v657-和-v710-版本开始引入"><code>force-init-stats</code></a>。你可以控制 TiDB 启动时是否在统计信息初始化完成后再对外提供服务。该配置项从 v7.2.0 起默认开启。</p><p>从 v7.1.0 开始,TiDB 引入了配置参数 <a href="/zh/tidb/stable/tidb-configuration-file#lite-init-stats-从-v710-版本开始引入"><code>lite-init-stats</code></a> 用于控制是否开启轻量级的统计信息初始化。</p><ul><li>当 <code>lite-init-stats</code> 为 <code>true</code> 时,统计信息初始化时列和索引的直方图、TopN、Count-Min Sketch 均不会加载到内存中。</li><li>当 <code>lite-init-stats</code> 为 <code>false</code> 时,统计信息初始化时索引和主键的直方图、TopN、Count-Min Sketch 会被加载到内存中,非主键列的直方图、TopN、Count-Min Sketch 不会加载到内存中。当优化器需要某一索引或者列的直方图、TopN、Count-Min Sketch 时,这些统计信息会被同步或异步加载到内存中。</li></ul><p><code>lite-init-stats</code> 默认值为 <code>true</code>,即开启轻量级的统计信息初始化。将 <code>lite-init-stats</code> 设置为 <code>true</code> 可以加速统计信息初始化,避免加载不必要的统计信息,从而降低 TiDB 的内存使用。</p><h2 id="统计信息的导入导出" style="position:relative"><a href="#%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%E7%9A%84%E5%AF%BC%E5%85%A5%E5%AF%BC%E5%87%BA" aria-label="统计信息的导入导出 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>统计信息的导入导出</h2><h3 id="导出统计信息" style="position:relative"><a href="#%E5%AF%BC%E5%87%BA%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF" aria-label="导出统计信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>导出统计信息</h3><p>统计信息的导出接口如下。</p><ul><li><p>通过以下接口可以获取数据库 <code>${db_name}</code> 中的表 <code>${table_name}</code> 的 JSON 格式的统计信息:</p><pre><code class="hljs language-"><div class="MuiBox-root css-1qhimia">http://${tidb-server-ip}:${tidb-server-status-port}/stats/dump/${db_name}/${table_name} </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p> 示例如下:</p><pre><code class="hljs language-"><div class="MuiBox-root css-1qhimia">curl -s http://127.0.0.1:10080/stats/dump/test/t1 -o /tmp/t1.json </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre></li><li><p>通过以下接口可以获取数据库 <code>${db_name}</code> 中的表 <code>${table_name}</code> 在指定时间上的 JSON 格式统计信息。指定的时间应在 GC SafePoint 之后。</p><pre><code class="hljs language-"><div class="MuiBox-root css-1qhimia">http://${tidb-server-ip}:${tidb-server-status-port}/stats/dump/${db_name}/${table_name}/${yyyyMMddHHmmss} </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre></li></ul><h3 id="导入统计信息" style="position:relative"><a href="#%E5%AF%BC%E5%85%A5%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF" aria-label="导入统计信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>导入统计信息</h3><div class="MuiBox-root css-1weqspv"><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation0 MuiAlert-root MuiAlert-standardInfo MuiAlert-standard css-152gid5" role="alert"><div class="MuiAlert-icon css-1l54tgj"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="InfoOutlinedIcon"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20, 12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10, 10 0 0,0 12,2M11,17H13V11H11V17Z"/></svg></div><div class="MuiAlert-message css-1xsto0d"><div class="MuiTypography-root MuiTypography-body1 MuiTypography-gutterBottom MuiAlertTitle-root css-17ioyuk">注意</div><p>启动 MySQL 客户端时,请使用 <code>--local-infile=1</code> 参数。</p></div></div></div><p>导入的统计信息一般是通过统计信息导出接口得到的 json 文件。</p><p>语法如下:</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">LOAD STATS <span class="hljs-string">'file_name'</span>; </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p><code>file_name</code> 为要导入的统计信息的文件名。</p><h2 id="锁定统计信息" style="position:relative"><a href="#%E9%94%81%E5%AE%9A%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF" aria-label="锁定统计信息 permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>锁定统计信息</h2><p>从 v6.5.0 开始,TiDB 引入了锁定统计信息的特性。当一张表或一个分区的统计信息被锁定以后,该表或分区的统计信息将无法被修改,也无法对该表进行 <code>ANALYZE</code> 操作。用例如下:</p><p>创建表 <code>t</code>,插入一些数据,在未锁定表 <code>t</code> 的统计信息的情况下成功执行 <code>ANALYZE</code> 语句。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">mysql<span class="hljs-operator">></span> <span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> t(a <span class="hljs-type">INT</span>, b <span class="hljs-type">INT</span>); Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected (<span class="hljs-number">0.03</span> sec) mysql<span class="hljs-operator">></span> <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> t <span class="hljs-keyword">VALUES</span> (<span class="hljs-number">1</span>,<span class="hljs-number">2</span>), (<span class="hljs-number">3</span>,<span class="hljs-number">4</span>), (<span class="hljs-number">5</span>,<span class="hljs-number">6</span>), (<span class="hljs-number">7</span>,<span class="hljs-number">8</span>); Query OK, <span class="hljs-number">4</span> <span class="hljs-keyword">rows</span> affected (<span class="hljs-number">0.00</span> sec) Records: <span class="hljs-number">4</span> Duplicates: <span class="hljs-number">0</span> Warnings: <span class="hljs-number">0</span> mysql<span class="hljs-operator">></span> ANALYZE <span class="hljs-keyword">TABLE</span> t; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected, <span class="hljs-number">1</span> warning (<span class="hljs-number">0.02</span> sec) mysql<span class="hljs-operator">></span> <span class="hljs-keyword">SHOW</span> WARNINGS; <span class="hljs-operator">+</span><span class="hljs-comment">-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-operator">|</span> Level <span class="hljs-operator">|</span> Code <span class="hljs-operator">|</span> Message <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-operator">|</span> Note <span class="hljs-operator">|</span> <span class="hljs-number">1105</span> <span class="hljs-operator">|</span> Analyze use auto adjusted sample rate <span class="hljs-number">1.000000</span> <span class="hljs-keyword">for</span> <span class="hljs-keyword">table</span> test.t, reason <span class="hljs-keyword">to</span> use this rate <span class="hljs-keyword">is</span> "Row count in stats_meta is much smaller compared with the row count got by PD, use min(1, 15000/4) as the sample-rate=1" <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-number">1</span> <span class="hljs-type">row</span> <span class="hljs-keyword">in</span> <span class="hljs-keyword">set</span> (<span class="hljs-number">0.00</span> sec) </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>锁定表 <code>t</code> 的统计信息,执行 <code>ANALYZE</code> 语句,warning 提示跳过对表 <code>t</code> 的 <code>ANALYZE</code>。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">mysql<span class="hljs-operator">></span> LOCK STATS t; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected (<span class="hljs-number">0.00</span> sec) mysql<span class="hljs-operator">></span> <span class="hljs-keyword">SHOW</span> STATS_LOCKED; <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+--------+</span> <span class="hljs-operator">|</span> Db_name <span class="hljs-operator">|</span> Table_name <span class="hljs-operator">|</span> Partition_name <span class="hljs-operator">|</span> Status <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+--------+</span> <span class="hljs-operator">|</span> test <span class="hljs-operator">|</span> t <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> locked <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+--------+</span> <span class="hljs-number">1</span> <span class="hljs-type">row</span> <span class="hljs-keyword">in</span> <span class="hljs-keyword">set</span> (<span class="hljs-number">0.01</span> sec) mysql<span class="hljs-operator">></span> ANALYZE <span class="hljs-keyword">TABLE</span> t; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected, <span class="hljs-number">2</span> warnings (<span class="hljs-number">0.00</span> sec) mysql<span class="hljs-operator">></span> <span class="hljs-keyword">SHOW</span> WARNINGS; <span class="hljs-operator">+</span><span class="hljs-comment">---------+------+-----------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-operator">|</span> Level <span class="hljs-operator">|</span> Code <span class="hljs-operator">|</span> Message <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------+-----------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-operator">|</span> Note <span class="hljs-operator">|</span> <span class="hljs-number">1105</span> <span class="hljs-operator">|</span> Analyze use auto adjusted sample rate <span class="hljs-number">1.000000</span> <span class="hljs-keyword">for</span> <span class="hljs-keyword">table</span> test.t, reason <span class="hljs-keyword">to</span> use this rate <span class="hljs-keyword">is</span> "use min(1, 110000/8) as the sample-rate=1" <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> Warning <span class="hljs-operator">|</span> <span class="hljs-number">1105</span> <span class="hljs-operator">|</span> <span class="hljs-keyword">skip</span> analyze locked <span class="hljs-keyword">table</span>: test.t <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------+-----------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-number">2</span> <span class="hljs-keyword">rows</span> <span class="hljs-keyword">in</span> <span class="hljs-keyword">set</span> (<span class="hljs-number">0.00</span> sec) </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>解锁表 <code>t</code> 的统计信息,成功执行 <code>ANALYZE</code> 语句。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">mysql<span class="hljs-operator">></span> UNLOCK STATS t; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected (<span class="hljs-number">0.01</span> sec) mysql<span class="hljs-operator">></span> ANALYZE <span class="hljs-keyword">TABLE</span> t; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected, <span class="hljs-number">1</span> warning (<span class="hljs-number">0.03</span> sec) mysql<span class="hljs-operator">></span> <span class="hljs-keyword">SHOW</span> WARNINGS; <span class="hljs-operator">+</span><span class="hljs-comment">-------+------+-----------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-operator">|</span> Level <span class="hljs-operator">|</span> Code <span class="hljs-operator">|</span> Message <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">-------+------+-----------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-operator">|</span> Note <span class="hljs-operator">|</span> <span class="hljs-number">1105</span> <span class="hljs-operator">|</span> Analyze use auto adjusted sample rate <span class="hljs-number">1.000000</span> <span class="hljs-keyword">for</span> <span class="hljs-keyword">table</span> test.t, reason <span class="hljs-keyword">to</span> use this rate <span class="hljs-keyword">is</span> "use min(1, 110000/8) as the sample-rate=1" <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">-------+------+-----------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-number">1</span> <span class="hljs-type">row</span> <span class="hljs-keyword">in</span> <span class="hljs-keyword">set</span> (<span class="hljs-number">0.00</span> sec) </div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>另外,你也可以通过 <code>LOCK STATS</code> 语句锁定分区的统计信息。用例如下:</p><p>创建分区表 <code>t</code>,插入一些数据,在未锁定分区 <code>p1</code> 的统计信息的情况下成功执行 <code>ANALYZE</code> 语句。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">mysql<span class="hljs-operator">></span> <span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> t(a <span class="hljs-type">INT</span>, b <span class="hljs-type">INT</span>) <span class="hljs-keyword">PARTITION</span> <span class="hljs-keyword">BY</span> <span class="hljs-keyword">RANGE</span> (a) (<span class="hljs-keyword">PARTITION</span> p0 <span class="hljs-keyword">VALUES</span> LESS THAN (<span class="hljs-number">10</span>), <span class="hljs-keyword">PARTITION</span> p1 <span class="hljs-keyword">VALUES</span> LESS THAN (<span class="hljs-number">20</span>), <span class="hljs-keyword">PARTITION</span> p2 <span class="hljs-keyword">VALUES</span> LESS THAN (<span class="hljs-number">30</span>)); Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected (<span class="hljs-number">0.03</span> sec) mysql<span class="hljs-operator">></span> <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> t <span class="hljs-keyword">VALUES</span> (<span class="hljs-number">1</span>,<span class="hljs-number">2</span>), (<span class="hljs-number">3</span>,<span class="hljs-number">4</span>), (<span class="hljs-number">5</span>,<span class="hljs-number">6</span>), (<span class="hljs-number">7</span>,<span class="hljs-number">8</span>); Query OK, <span class="hljs-number">4</span> <span class="hljs-keyword">rows</span> affected (<span class="hljs-number">0.00</span> sec) Records: <span class="hljs-number">4</span> Duplicates: <span class="hljs-number">0</span> Warnings: <span class="hljs-number">0</span> mysql<span class="hljs-operator">></span> ANALYZE <span class="hljs-keyword">TABLE</span> t; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected, <span class="hljs-number">6</span> warning (<span class="hljs-number">0.02</span> sec) mysql<span class="hljs-operator">></span> <span class="hljs-keyword">SHOW</span> WARNINGS; <span class="hljs-operator">+</span><span class="hljs-comment">---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-operator">|</span> Level <span class="hljs-operator">|</span> Code <span class="hljs-operator">|</span> Message <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-operator">|</span> Warning <span class="hljs-operator">|</span> <span class="hljs-number">1105</span> <span class="hljs-operator">|</span> disable <span class="hljs-keyword">dynamic</span> pruning due <span class="hljs-keyword">to</span> t has <span class="hljs-keyword">no</span> <span class="hljs-keyword">global</span> stats <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> Note <span class="hljs-operator">|</span> <span class="hljs-number">1105</span> <span class="hljs-operator">|</span> Analyze use auto adjusted sample rate <span class="hljs-number">1.000000</span> <span class="hljs-keyword">for</span> <span class="hljs-keyword">table</span> test.t<span class="hljs-string">'s partition p0, reason to use this rate is "Row count in stats_meta is much smaller compared with the row count got by PD, use min(1, 15000/4) as the sample-rate=1" | | Warning | 1105 | disable dynamic pruning due to t has no global stats | | Note | 1105 | Analyze use auto adjusted sample rate 1.000000 for table test.t'</span>s <span class="hljs-keyword">partition</span> p1, reason <span class="hljs-keyword">to</span> use this rate <span class="hljs-keyword">is</span> "TiDB assumes that the table is empty, use sample-rate=1" <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> Warning <span class="hljs-operator">|</span> <span class="hljs-number">1105</span> <span class="hljs-operator">|</span> disable <span class="hljs-keyword">dynamic</span> pruning due <span class="hljs-keyword">to</span> t has <span class="hljs-keyword">no</span> <span class="hljs-keyword">global</span> stats <span class="hljs-operator">|</span> <span class="hljs-operator">|</span> Note <span class="hljs-operator">|</span> <span class="hljs-number">1105</span> <span class="hljs-operator">|</span> Analyze use auto adjusted sample rate <span class="hljs-number">1.000000</span> <span class="hljs-keyword">for</span> <span class="hljs-keyword">table</span> test.t<span class="hljs-string">'s partition p2, reason to use this rate is "TiDB assumes that the table is empty, use sample-rate=1" | +---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 6 rows in set (0.01 sec) </span></div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>锁定分区 <code>p1</code> 的统计信息,执行 <code>ANALYZE</code> 语句,warning 提示跳过对分区 <code>p1</code> 的 <code>ANALYZE</code>。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">mysql<span class="hljs-operator">></span> LOCK STATS t <span class="hljs-keyword">PARTITION</span> p1; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected (<span class="hljs-number">0.00</span> sec) mysql<span class="hljs-operator">></span> <span class="hljs-keyword">SHOW</span> STATS_LOCKED; <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+--------+</span> <span class="hljs-operator">|</span> Db_name <span class="hljs-operator">|</span> Table_name <span class="hljs-operator">|</span> Partition_name <span class="hljs-operator">|</span> Status <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+--------+</span> <span class="hljs-operator">|</span> test <span class="hljs-operator">|</span> t <span class="hljs-operator">|</span> p1 <span class="hljs-operator">|</span> locked <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------------+----------------+--------+</span> <span class="hljs-number">1</span> <span class="hljs-type">row</span> <span class="hljs-keyword">in</span> <span class="hljs-keyword">set</span> (<span class="hljs-number">0.00</span> sec) mysql<span class="hljs-operator">></span> ANALYZE <span class="hljs-keyword">TABLE</span> t <span class="hljs-keyword">PARTITION</span> p1; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected, <span class="hljs-number">2</span> warnings (<span class="hljs-number">0.01</span> sec) mysql<span class="hljs-operator">></span> <span class="hljs-keyword">SHOW</span> WARNINGS; <span class="hljs-operator">+</span><span class="hljs-comment">---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-operator">|</span> Level <span class="hljs-operator">|</span> Code <span class="hljs-operator">|</span> Message <span class="hljs-operator">|</span> <span class="hljs-operator">+</span><span class="hljs-comment">---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+</span> <span class="hljs-operator">|</span> Note <span class="hljs-operator">|</span> <span class="hljs-number">1105</span> <span class="hljs-operator">|</span> Analyze use auto adjusted sample rate <span class="hljs-number">1.000000</span> <span class="hljs-keyword">for</span> <span class="hljs-keyword">table</span> test.t<span class="hljs-string">'s partition p1, reason to use this rate is "TiDB assumes that the table is empty, use sample-rate=1" | | Warning | 1105 | skip analyze locked table: test.t partition (p1) | +---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) </span></div><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1rmx1rm" tabindex="0" type="button" aria-label="Toggle code wrap"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="WrapTextIcon"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg></button><button class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-fxo539" tabindex="0" type="button" aria-label="copy"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeInherit css-1cw4hi4" focusable="false" aria-hidden="true" viewbox="0 0 24 24" data-testid="ContentCopyIcon"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg></button></code></pre><p>解锁分区 <code>p1</code> 的统计信息,成功执行 <code>ANALYZE</code> 语句。</p><pre><code class="hljs language-sql"><div class="MuiBox-root css-1qhimia">mysql<span class="hljs-operator">></span> UNLOCK STATS t <span class="hljs-keyword">PARTITION</span> p1; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected (<span class="hljs-number">0.00</span> sec) mysql<span class="hljs-operator">></span> ANALYZE <span class="hljs-keyword">TABLE</span> t <span class="hljs-keyword">PARTITION</span> p1; Query OK, <span class="hljs-number">0</span> <span class="hljs-keyword">rows</span> affected, <span class="hljs-number">1</span> warning (<span class="hljs-number">0.01</span> sec) mysql<span class="hljs-operator">></span> <span class="hljs-keyword">SHOW</span> WARNINGS; <span class="hljs-operator">+</span><span class="hljs-comment">-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+</span>
推荐文章