Docs Menu
Docs Home
/
MongoDB ๋งค๋‰ด์–ผ
/ / /

$planCacheStats

์ด ํŽ˜์ด์ง€์˜ ๋‚ด์šฉ

  • ์ •์˜
  • ๊ณ ๋ ค ์‚ฌํ•ญ
  • ํŒŒ์ดํ”„๋ผ์ธ
  • ์ œํ•œ ์‚ฌํ•ญ
  • ์•ก์„ธ์Šค ์ œ์–ด
  • ํŽธ์ง‘
  • ์ฝ๊ธฐ ์„ค์ •
  • ์ถœ๋ ฅ
  • ์˜ˆ์‹œ
  • ์ฟผ๋ฆฌ ์บ์‹œ์˜ ๋ชจ๋“  ํ•ญ๋ชฉ์— ํ•ด๋‹นํ•˜๋Š” ์ •๋ณด ๋ฐ˜ํ™˜ํ•˜๊ธฐ
  • ์ฟผ๋ฆฌ ํ•ด์‹œ์— ๋Œ€ํ•œ ์บ์‹œ ํ•ญ๋ชฉ ์„ธ๋ถ€ ์ •๋ณด ์ฐพ๊ธฐ
$planCacheStats

์ปฌ๋ ‰์…˜ ์— ๋Œ€ํ•œ ๊ณ„ํš ์บ์‹œ ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ด ๋‹จ๊ณ„๋Š” ๊ฐ ๊ณ„ํš ์บ์‹œ ํ•ญ๋ชฉ์— ๋Œ€ํ•œ ๋ฌธ์„œ ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

$planCacheStats ๋‹จ๊ณ„๋Š” ํŒŒ์ดํ”„๋ผ์ธ์˜ ์ฒซ ๋ฒˆ์งธ ๋‹จ๊ณ„์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด ๋‹จ๊ณ„์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ตฌ๋ฌธ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

{
$planCacheStats: {
allHosts: <boolean>
}
}

$planCacheStats ์• ๊ทธ๋ฆฌ๊ฒŒ์ด์…˜ ๋‹จ๊ณ„์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์˜ต์…˜์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ต์…˜
์„ค๋ช…

allHosts

$planCacheStats ์• ๊ทธ๋ฆฌ๊ฒŒ์ด์…˜ ๋‹จ๊ณ„๊ฐ€ ์ƒค๋“œ cluster์˜ ๋…ธ๋“œ๋ฅผ ๋Œ€์ƒ์œผ๋กœ ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.

  • true ์ธ ๊ฒฝ์šฐ, mongos ๋Š” ๋Œ€์ƒ collection์—์„œ ํ•˜๋‚˜ ์ด์ƒ์˜ ์ฒญํฌ๋ฅผ ํฌํ•จํ•˜๋Š” ์˜ํ–ฅ์„ ๋ฐ›์€ ๊ฐ ์ƒค๋“œ์— ๋Œ€ํ•ด ๋ชจ๋“  ๋…ธ๋“œ(ํ”„๋ผ์ด๋จธ๋ฆฌ ๋ฐ ์„ธ์ปจ๋”๋ฆฌ)์— $planCacheStats ์• ๊ทธ๋ฆฌ๊ฒŒ์ด์…˜ ๋‹จ๊ณ„๋ฅผ ๋ธŒ๋กœ๋“œ์บ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค.

  • false ์ธ ๊ฒฝ์šฐ $planCacheStats ์• ๊ทธ๋ฆฌ๊ฒŒ์ด์…˜ ๋‹จ๊ณ„๋Š” ์ฝ๊ธฐ ์„ค์ • (read preference) ์„ ๋”ฐ๋ฅด๊ณ  ๋Œ€์ƒ ๋ณต์ œ๋ณธ ์„ธํŠธ ํ”„๋ผ์ด๋จธ๋ฆฌ์—์„œ๋งŒ ๊ณ„ํš ์บ์‹œ๋ฅผ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.

allHosts ๊ฐ€ true ๋กœ ์„ค์ •๋œ ๊ฒฝ์šฐ ๋ณต์ œ๋ณธ ์„ธํŠธ ๋ฐ ๋…๋ฆฝํ˜• ์„œ๋ฒ„๋Š” ํŒŒ์ดํ”„๋ผ์ธ ๊ตฌ๋ฌธ ๋ถ„์„ ์ค‘์— ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ด ์˜ต์…˜์€ ์ƒค๋”ฉ๋œ cluster์—์„œ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ธฐ๋ณธ๊ฐ’์ž…๋‹ˆ๋‹ค: false

๋ฒ„์ „ 7.1์— ์ƒˆ๋กœ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

ํŒ

๋‹ค์Œ๋„ ์ฐธ์กฐํ•˜์„ธ์š”.

$planCacheStats ๋Š” ์ง‘๊ณ„ ํŒŒ์ดํ”„๋ผ์ธ์˜ ์ฒซ ๋ฒˆ์งธ ๋‹จ๊ณ„์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

authorization๋ฅผ ํ†ตํ•ด ์‹คํ–‰๋˜๋Š” ์‹œ์Šคํ…œ์—์„œ ์‚ฌ์šฉ์ž๋Š” ์ปฌ๋ ‰์…˜์— ๋Œ€ํ•œ planCacheRead ๊ถŒํ•œ์ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Queryable Encryption์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ $planCacheStats ๋‹จ๊ณ„์—์„œ๋Š” ์ž‘์—…์ด ์ •์ƒ์ ์œผ๋กœ ์บ์‹œ๋˜๋”๋ผ๋„ ์•”ํ˜ธํ™”๋œ ์ปฌ๋ ‰์…˜์— ๋Œ€ํ•œ ์ž‘์—…์„ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค.

allHosts ์˜ต์…˜์ด false ๋กœ ์„ค์ •ํ•˜๋‹ค ๊ฒฝ์šฐ $planCacheStats ๋Š” ์ฝ๊ธฐ ์„ค์ • (read preference) ์„ ๋”ฐ๋ผ ๊ณ„ํš ์บ์‹œ ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•  ํ˜ธ์ŠคํŒ…ํ•˜๋‹ค ๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ๋‹ค๋ฅธ ๋…ธ๋“œ๋ฅผ ๋Œ€์ƒ์œผ๋กœ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๊ฐ ๋ณต์ œ๋ณธ ์„ธํŠธ ๋…ธ๋“œ๋Š” ์„œ๋กœ ๋‹ค๋ฅธ ์ฝ๊ธฐ ๋ช…๋ น์„ ์ˆ˜์‹ ํ•˜๊ณ  ๋‹ค๋ฅธ ๋…ธ๋“œ์™€ ๋‹ค๋ฅธ ๊ณ„ํš ์บ์‹œ ์ •๋ณด๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ๋ณต์ œ๋ณธ ์„ธํŠธ ๋˜๋Š” ๋ถ„ํ• ๋œ ํด๋Ÿฌ์Šคํ„ฐ์—์„œ $planCacheStats๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์€ ์ผ๋ฐ˜์ ์ธ ์ฝ๊ธฐ ๊ธฐ๋ณธ ์„ค์ • ๊ทœ์น™์„ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค. ์ฆ‰, ๋ณต์ œ๋ณธ ์„ธํŠธ์—์„œ๋Š” ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ํ•œ ๋…ธ๋“œ๋กœ๋ถ€ํ„ฐ๋งŒ ๊ณ„ํš ์บ์‹œ ์ •๋ณด๋ฅผ ์ˆ˜์ง‘ํ•˜๊ณ , ์ƒค๋“œ ํด๋Ÿฌ์Šคํ„ฐ์—์„œ๋Š” ๊ฐ ์ƒค๋“œ ๋ณต์ œ๋ณธ ์„ธํŠธ์˜ ๋…ธ๋“œ๋กœ๋ถ€ํ„ฐ๋งŒ ๊ณ„ํš ์บ์‹œ ์ •๋ณด๋ฅผ ์ˆ˜์ง‘ํ•˜๋Š” ์ž‘์—…์ž…๋‹ˆ๋‹ค.

๋ฒ„์ „ 7.0์—์„œ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

$planCacheStats์˜ ์ถœ๋ ฅ์€ ์ฟผ๋ฆฌ๋ฅผ ์™„๋ฃŒํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ ์ฟผ๋ฆฌ ์—”์ง„์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง‘๋‹ˆ๋‹ค. $planCacheStats์˜ version ํ•„๋“œ ๊ฐ’์€ ์‚ฌ์šฉ๋œ ์ฟผ๋ฆฌ ์—”์ง„์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

ํด๋ž˜์‹ ์‹คํ–‰ ์—”์ง„ ์„ ์‚ฌ์šฉํ•˜๋Š” ์ฟผ๋ฆฌ์˜ ๊ฒฝ์šฐ $planCacheStats ๋Š” ๋‹ค์Œ๊ณผ ์œ ์‚ฌํ•œ ๋ฌธ์„œ ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

{
"version" : 1,
"createdFromQuery" : <document>,
"planCacheShapeHash" : <hexadecimal string>,
"planCacheKey" : <hexadecimal string>,
"isActive" : <boolean>,
"works" : <NumberLong>,
"cachedPlan" : {
"stage" : <STAGE1>,
"filter" : <document>,
"inputStage" : {
"stage" : <STAGE2>,
...
}
},
"timeOfCreation" : <date>,
"creationExecStats" : [ // Exec Stats Document for each candidate plan
{
"nReturned" : <num>,
"executionTimeMillisEstimate" : <num>,
"totalKeysExamined" : <num>,
"totalDocsExamined" :<num>,
"executionStages" : {
"stage" : <STAGE A>,
...
"inputStage" : {
"stage" : <STAGE B>,
...
}
}
},
...
],
"candidatePlanScores" : [
<number>,
...
],
"indexFilterSet" : <boolean>,
"estimatedSizeBytes" : <num>,
"querySettings" : <document>,
"host" : <string>,
"shard" : <string>
}

๊ฐ ๋ฌธ์„œ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ์ฟผ๋ฆฌ ๊ณ„ํš ๋ฐ ์‹คํ–‰ ํ†ต๊ณ„๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•„๋“œ
์„ค๋ช…

version

์ฟผ๋ฆฌ๋ฅผ ์™„๋ฃŒํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ ์ฟผ๋ฆฌ ์—”์ง„์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ˆซ์ž์ž…๋‹ˆ๋‹ค.

createdFromQuery

์ด ์บ์‹œ ํ•ญ๋ชฉ์„ ์ƒ์„ฑํ•œ ํŠน์ • ์ฟผ๋ฆฌ๊ฐ€ ํฌํ•จ๋œ ๋ฌธ์„œ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

{
"query" : <document>,
"sort" : <document>,
"projection" : <document>
}

isActive

ํ•ญ๋ชฉ์ด ํ™œ์„ฑ ์ƒํƒœ์ธ์ง€ ๋น„ํ™œ์„ฑ ์ƒํƒœ์ธ์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ถ€์šธ

  • ํ™œ์„ฑํ™”๋œ ๊ฒฝ์šฐ, ์ฟผ๋ฆฌ ํ”Œ๋ž˜๋„ˆ๊ฐ€ ํ˜„์žฌ ํ•ญ๋ชฉ์„ ์‚ฌ์šฉํ•ด ์ฟผ๋ฆฌ ๊ณ„ํš์„ ์ƒ์„ฑํ•˜๊ณ  ์žˆ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.

  • ๋น„ํ™œ์„ฑ ์ƒํƒœ์ธ ๊ฒฝ์šฐ ์ฟผ๋ฆฌ ํ”Œ๋ž˜๋„ˆ๋Š” ํ˜„์žฌ ์ด ํ•ญ๋ชฉ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ฟผ๋ฆฌ ๊ณ„ํš์„ ์ƒ์„ฑํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๊ณ„ํš ์บ์‹œ ํ•ญ๋ชฉ ์ƒํƒœ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

planCacheShapeHash

์ฟผ๋ฆฌ ํ˜•ํƒœ string ์˜ ํ•ด์‹œ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” 16์ง„์ˆ˜ ์ž…๋‹ˆ๋‹ค. explain.queryPlanner.planCacheShapeHash ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

MongoDB 8.0 ๋ถ€ํ„ฐ ๊ธฐ์กด queryHash ํ•„๋“œ ์˜ ์ด๋ฆ„์ด planCacheShapeHash ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด์ „ MongoDB ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ planCacheShapeHash queryHash ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

planCacheKey

์ด ์ฟผ๋ฆฌ ์™€ ์—ฐ๊ฒฐ๋œ ๊ณ„ํš ์บ์‹œ ํ•ญ๋ชฉ์„ ์ฐพ๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ํ‚ค์˜ ํ•ด์‹œ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” 16์ง„์ˆ˜ string ์ž…๋‹ˆ๋‹ค. ๊ณ„ํš ์บ์‹œ ํ‚ค๋Š” ๊ณ„ํš ์บ์‹œ ์ฟผ๋ฆฌ ํ˜•ํƒœ ์™€ ํ•ด๋‹น ํ˜•ํƒœ์— ๋Œ€ํ•ด ํ˜„์žฌ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ธ๋ฑ์Šค ๋ชจ๋‘์˜ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค. explain.queryPlanner.planCacheKey ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

cachedPlan

์บ์‹œ๋œ ๊ณ„ํš์˜ ์„ธ๋ถ€ ์ •๋ณด์ž…๋‹ˆ๋‹ค. cachedPlan ์— ํฌํ•จ๋œ ํ•„๋“œ๋Š” ์ฟผ๋ฆฌ ๊ฐ€ ํด๋ž˜์‹ ์—”์ง„ ์„ ์‚ฌ์šฉํ•˜์—ฌ ์™„๋ฃŒ๋˜์—ˆ๋Š”์ง€, ์•„๋‹ˆ๋ฉด ์Šฌ๋กฏ ๊ธฐ๋ฐ˜ ์ฟผ๋ฆฌ ์‹คํ–‰ ์—”์ง„ ์„ ์‚ฌ์šฉํ•˜์—ฌ ์™„๋ฃŒ๋˜์—ˆ๋Š”์ง€์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง‘๋‹ˆ๋‹ค. ์ฟผ๋ฆฌ ๊ณ„ํš์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ explain.queryPlanner ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

works

์ฟผ๋ฆฌ ํ”Œ๋ž˜๋„ˆ๊ฐ€ ํ›„๋ณด ๊ณ„ํš์„ ํ‰๊ฐ€ํ•˜๋Š” ์‹œ๋„ ๊ธฐ๊ฐ„ ๋™์•ˆ ์ฟผ๋ฆฌ ์‹คํ–‰ ๊ณ„ํš์—์„œ ์ˆ˜ํ–‰ํ•œ '์ž‘์—… ๋‹จ์œ„'์˜ ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ explain.executionStats.executionStages.works ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

timeOfCreation

ํ•ญ๋ชฉ์˜ ์ƒ์„ฑ ์‹œ๊ฐ„์ž…๋‹ˆ๋‹ค.

creationExecStats

์‹คํ–‰ ํ†ต๊ณ„ ๋ฌธ์„œ์˜ ๋ฐฐ์—ด. ๋ฐฐ์—ด์—๋Š” ๊ฐ ํ›„๋ณด ๊ณ„ํš์— ๋Œ€ํ•œ ๋ฌธ์„œ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

์‹คํ–‰ ํ†ต๊ณ„์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ explain.executionStats๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

candidatePlanScores

creationExecStats ๋ฐฐ์—ด์— ๋‚˜์—ด๋œ ํ›„๋ณด ๊ณ„ํš์— ๋Œ€ํ•œ ์ ์ˆ˜์˜ ๋ฐฐ์—ด์ž…๋‹ˆ๋‹ค.

indexFilterSet

๊ณ„ํš ์บ์‹œ ์ฟผ๋ฆฌ ํ˜•ํƒœ ์— ๋Œ€ํ•œ ์ธ๋ฑ์Šค ํ•„ํ„ฐํ•˜๋‹ค๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ถ€์šธ์ž…๋‹ˆ๋‹ค.

estimatedSizeBytes

๊ณ„ํš ์บ์‹œ ํ•ญ๋ชฉ์˜ ์˜ˆ์ƒ ํฌ๊ธฐ(๋ฐ”์ดํŠธ)์ž…๋‹ˆ๋‹ค.

querySettings

๋ฒ„์ „ 8.0์— ์ถ”๊ฐ€ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์ด์ „์— setQuerySettings๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ค์ •ํ•˜๋‹ค ์ฟผ๋ฆฌ ์„ค์ •์ด ํฌํ•จ๋œ ๋ฌธ์„œ ์ž…๋‹ˆ๋‹ค.

querySettings: {
indexHints: [ {
ns: { db: <string>, coll: <string> },
allowedIndexes: <array>
}, ... ],
queryFramework: <string>
}

querySettings ํ•„๋“œ:

ํ•„๋“œ
์œ ํ˜•
์„ค๋ช…

indexHints.ns

๋ฌธ์„œ

์ธ๋ฑ์Šค ํžŒํŠธ๋ฅผ ์œ„ํ•œ ๋„ค์ž„์ŠคํŽ˜์ด์Šค์ž…๋‹ˆ๋‹ค.

db

๋ฌธ์ž์—ด

์ธ๋ฑ์Šค ํžŒํŠธ์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

coll

๋ฌธ์ž์—ด

์ธ๋ฑ์Šค ํžŒํŠธ์— ๋Œ€ํ•œ ์ปฌ๋ ‰์…˜ ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

indexHints.allowedIndexes

๋ฐฐ์—ด

์ธ๋ฑ์Šค ํžŒํŠธ์— ๋Œ€ํ•œ ์ธ๋ฑ์Šค ๋ฐฐ์—ด์ž…๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ธ๋ฑ์Šค ๋ฐ hint() ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

queryFramework

๋ฌธ์ž์—ด

์ฟผ๋ฆฌ ํ”„๋ ˆ์ž„์›Œํฌ string ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

host

๊ณ„ํš ์บ์‹œ ์ •๋ณด๊ฐ€ ๋ฐ˜ํ™˜๋œ mongod ์ธ์Šคํ„ด์Šค์˜ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„ ๋ฐ ํฌํŠธ์ž…๋‹ˆ๋‹ค.

์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ ์—์„œ ์‹คํ–‰ ํ•˜๋Š” ๊ฒฝ์šฐ ์ž‘์—… ์€ ๊ฐ ์ƒค๋“œ ๋ณต์ œ๋ณธ ์„ธํŠธ ์˜ ๋‹จ์ผ ๋ฉค๋ฒ„ ๋กœ๋ถ€ํ„ฐ ๊ณ„ํš ์บ์‹œ ํ•ญ๋ชฉ ์ •๋ณด ๋ฅผ ๋ฐ˜ํ™˜ ํ•ฉ๋‹ˆ๋‹ค . ์ด ๋ฉค๋ฒ„๋Š” ์ƒค๋“œ ๋ฐ ํ˜ธ์ŠคํŒ…ํ•˜๋‹คํ•„๋“œ๋กœ ์‹๋ณ„๋ฉ๋‹ˆ๋‹ค. ํŽธ์ง‘์„ ์ฐธ์กฐ ํŽธ์ง‘.

shard

๊ฐ€ ์บ์‹œ ํ•ญ๋ชฉ์„ $planCacheStats ๊ฒ€์ƒ‰ํ•œ ์ƒค๋“œ ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ์‹คํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ์—๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์Šฌ๋กฏ ๊ธฐ๋ฐ˜ ์ฟผ๋ฆฌ ์‹คํ–‰ ์—”์ง„์„ ์‚ฌ์šฉํ•˜๋Š” ์ฟผ๋ฆฌ์˜ ๊ฒฝ์šฐ $planCacheStats ๋Š” ๋‹ค์Œ๊ณผ ์œ ์‚ฌํ•œ ๋ฌธ์„œ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

{
"version" : 2,
"planCacheShapeHash" : <hexadecimal string>,
"planCacheKey" : <hexadecimal string>,
"isActive" : <boolean>,
"works" : <NumberLong>,
"cachedPlan" : {
"slots" : <string>,
"stages": <string>
},
"indexFilterSet" : <boolean>,
"estimatedSizeBytes" : <num>,
"querySettings" : <document>,
"host" : <string>
}

๊ฐ ๋ฌธ์„œ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ์ฟผ๋ฆฌ ๊ณ„ํš ๋ฐ ์‹คํ–‰ ํ†ต๊ณ„๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•„๋“œ
์„ค๋ช…

version

์ฟผ๋ฆฌ๋ฅผ ์™„๋ฃŒํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ ์ฟผ๋ฆฌ ์—”์ง„์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ˆซ์ž์ž…๋‹ˆ๋‹ค.

planCacheShapeHash

์ฟผ๋ฆฌ ํ˜•ํƒœ string ์˜ ํ•ด์‹œ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” 16์ง„์ˆ˜ ์ž…๋‹ˆ๋‹ค. explain.queryPlanner.planCacheShapeHash ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

MongoDB 8.0 ๋ถ€ํ„ฐ ๊ธฐ์กด queryHash ํ•„๋“œ ์˜ ์ด๋ฆ„์ด planCacheShapeHash ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด์ „ MongoDB ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ planCacheShapeHash queryHash ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

planCacheKey

์ด ์ฟผ๋ฆฌ ์™€ ์—ฐ๊ฒฐ๋œ ๊ณ„ํš ์บ์‹œ ํ•ญ๋ชฉ์„ ์ฐพ๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ํ‚ค์˜ ํ•ด์‹œ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” 16์ง„์ˆ˜ string ์ž…๋‹ˆ๋‹ค. ๊ณ„ํš ์บ์‹œ ํ‚ค๋Š” ๊ณ„ํš ์บ์‹œ ์ฟผ๋ฆฌ ํ˜•ํƒœ ์™€ ํ•ด๋‹น ํ˜•ํƒœ์— ๋Œ€ํ•ด ํ˜„์žฌ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ธ๋ฑ์Šค ๋ชจ๋‘์˜ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค. explain.queryPlanner.planCacheKey ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

isActive

ํ•ญ๋ชฉ์ด ํ™œ์„ฑ ์ƒํƒœ์ธ์ง€ ๋น„ํ™œ์„ฑ ์ƒํƒœ์ธ์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ถ€์šธ

  • ํ™œ์„ฑํ™”๋œ ๊ฒฝ์šฐ, ์ฟผ๋ฆฌ ํ”Œ๋ž˜๋„ˆ๊ฐ€ ํ˜„์žฌ ํ•ญ๋ชฉ์„ ์‚ฌ์šฉํ•ด ์ฟผ๋ฆฌ ๊ณ„ํš์„ ์ƒ์„ฑํ•˜๊ณ  ์žˆ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.

  • ๋น„ํ™œ์„ฑ ์ƒํƒœ์ธ ๊ฒฝ์šฐ ์ฟผ๋ฆฌ ํ”Œ๋ž˜๋„ˆ๋Š” ํ˜„์žฌ ์ด ํ•ญ๋ชฉ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ฟผ๋ฆฌ ๊ณ„ํš์„ ์ƒ์„ฑํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๊ณ„ํš ์บ์‹œ ํ•ญ๋ชฉ ์ƒํƒœ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

works

์ฟผ๋ฆฌ ํ”Œ๋ž˜๋„ˆ๊ฐ€ ํ›„๋ณด ๊ณ„ํš์„ ํ‰๊ฐ€ํ•˜๋Š” ์‹œ๋„ ๊ธฐ๊ฐ„ ๋™์•ˆ ์ฟผ๋ฆฌ ์‹คํ–‰ ๊ณ„ํš์—์„œ ์ˆ˜ํ–‰ํ•œ '์ž‘์—… ๋‹จ์œ„'์˜ ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ explain.executionStats.executionStages.works ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

cachedPlan

์บ์‹œ๋œ ๊ณ„ํš์˜ ์„ธ๋ถ€ ์ •๋ณด์ž…๋‹ˆ๋‹ค. cachedPlan ์— ํฌํ•จ๋œ ํ•„๋“œ๋Š” ์ฟผ๋ฆฌ ๊ฐ€ ํด๋ž˜์‹ ์—”์ง„ ์„ ์‚ฌ์šฉํ•˜์—ฌ ์™„๋ฃŒ๋˜์—ˆ๋Š”์ง€, ์•„๋‹ˆ๋ฉด ์Šฌ๋กฏ ๊ธฐ๋ฐ˜ ์ฟผ๋ฆฌ ์‹คํ–‰ ์—”์ง„ ์„ ์‚ฌ์šฉํ•˜์—ฌ ์™„๋ฃŒ๋˜์—ˆ๋Š”์ง€์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง‘๋‹ˆ๋‹ค. ์ฟผ๋ฆฌ ๊ณ„ํš์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ explain.queryPlanner ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

indexFilterSet

๊ณ„ํš ์บ์‹œ ์ฟผ๋ฆฌ ํ˜•ํƒœ ์— ๋Œ€ํ•œ ์ธ๋ฑ์Šค ํ•„ํ„ฐํ•˜๋‹ค๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ถ€์šธ์ž…๋‹ˆ๋‹ค.

estimatedSizeBytes

๊ณ„ํš ์บ์‹œ ํ•ญ๋ชฉ์˜ ์˜ˆ์ƒ ํฌ๊ธฐ(๋ฐ”์ดํŠธ)์ž…๋‹ˆ๋‹ค.

querySettings

๋ฒ„์ „ 8.0์— ์ถ”๊ฐ€ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์ด์ „์— setQuerySettings๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ค์ •ํ•˜๋‹ค ์ฟผ๋ฆฌ ์„ค์ •์ด ํฌํ•จ๋œ ๋ฌธ์„œ ์ž…๋‹ˆ๋‹ค.

querySettings: {
indexHints: [ {
ns: { db: <string>, coll: <string> },
allowedIndexes: <array>
}, ... ],
queryFramework: <string>
}

querySettings ํ•„๋“œ:

ํ•„๋“œ
์œ ํ˜•
์„ค๋ช…

indexHints.ns

๋ฌธ์„œ

์ธ๋ฑ์Šค ํžŒํŠธ๋ฅผ ์œ„ํ•œ ๋„ค์ž„์ŠคํŽ˜์ด์Šค์ž…๋‹ˆ๋‹ค.

db

๋ฌธ์ž์—ด

์ธ๋ฑ์Šค ํžŒํŠธ์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

coll

๋ฌธ์ž์—ด

์ธ๋ฑ์Šค ํžŒํŠธ์— ๋Œ€ํ•œ ์ปฌ๋ ‰์…˜ ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

indexHints.allowedIndexes

๋ฐฐ์—ด

์ธ๋ฑ์Šค ํžŒํŠธ์— ๋Œ€ํ•œ ์ธ๋ฑ์Šค ๋ฐฐ์—ด์ž…๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ธ๋ฑ์Šค ๋ฐ hint() ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

queryFramework

๋ฌธ์ž์—ด

์ฟผ๋ฆฌ ํ”„๋ ˆ์ž„์›Œํฌ string ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

host

๊ณ„ํš ์บ์‹œ ์ •๋ณด๊ฐ€ ๋ฐ˜ํ™˜๋œ mongod ์ธ์Šคํ„ด์Šค์˜ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„ ๋ฐ ํฌํŠธ์ž…๋‹ˆ๋‹ค.

์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ ์—์„œ ์‹คํ–‰ ํ•˜๋Š” ๊ฒฝ์šฐ ์ž‘์—… ์€ ๊ฐ ์ƒค๋“œ ๋ณต์ œ๋ณธ ์„ธํŠธ ์˜ ๋‹จ์ผ ๋ฉค๋ฒ„ ๋กœ๋ถ€ํ„ฐ ๊ณ„ํš ์บ์‹œ ํ•ญ๋ชฉ ์ •๋ณด ๋ฅผ ๋ฐ˜ํ™˜ ํ•ฉ๋‹ˆ๋‹ค . ์ด ๋ฉค๋ฒ„๋Š” ์ƒค๋“œ ๋ฐ ํ˜ธ์ŠคํŒ…ํ•˜๋‹คํ•„๋“œ๋กœ ์‹๋ณ„๋ฉ๋‹ˆ๋‹ค. ํŽธ์ง‘์„ ์ฐธ์กฐ ํŽธ์ง‘.

์ด ์„น์…˜์˜ ์˜ˆ์‹œ์—์„œ๋Š” ๋‹ค์Œ์˜ orders collection์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

db.orders.insertMany( [
{ "_id" : 1, "item" : "abc", "price" : NumberDecimal("12"), "quantity" : 2, "type": "apparel" },
{ "_id" : 2, "item" : "jkl", "price" : NumberDecimal("20"), "quantity" : 1, "type": "electronics" },
{ "_id" : 3, "item" : "abc", "price" : NumberDecimal("10"), "quantity" : 5, "type": "apparel" },
{ "_id" : 4, "item" : "abc", "price" : NumberDecimal("8"), "quantity" : 10, "type": "apparel" },
{ "_id" : 5, "item" : "jkl", "price" : NumberDecimal("15"), "quantity" : 15, "type": "electronics" }
] )

์ปฌ๋ ‰์…˜์— ๋‹ค์Œ ์ธ๋ฑ์Šค๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

db.orders.createIndex( { item: 1 } );
db.orders.createIndex( { item: 1, quantity: 1 } );
db.orders.createIndex( { quantity: 1 } );
db.orders.createIndex( { quantity: 1, type: 1 } );
db.orders.createIndex(
{ item: 1, price: 1 },
{ partialFilterExpression: { price: { $gte: NumberDecimal("10")} } }
);

์ฐธ๊ณ 

์ธ๋ฑ์Šค { item: 1, price: 1 } ์€ ๋ถ€๋ถ„ ์ธ๋ฑ์Šค์ด๋ฉฐ price ํ•„๋“œ๊ฐ€ NumberDecimal("10")๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์€ ์ธ๋ฑ์Šค๋œ ๋ฌธ์„œ๋งŒ ์ธ๋ฑ์‹ฑํ•ฉ๋‹ˆ๋‹ค.

collection์— ๋Œ€ํ•ด ๋ช‡ ๊ฐ€์ง€ ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

db.orders.find( { item: "abc", price: { $gte: NumberDecimal("10") } } )
db.orders.find( { item: "abc", price: { $gte: NumberDecimal("5") } } )
db.orders.find( { quantity: { $gte: 20 } } )
db.orders.find( { quantity: { $gte: 5 }, type: "apparel" } )

์•ž์˜ ์ฟผ๋ฆฌ๋Š” ์Šฌ๋กฏ ๊ธฐ๋ฐ˜ ์ฟผ๋ฆฌ ์‹คํ–‰ ์—”์ง„์„ ์‚ฌ์šฉํ•˜์—ฌ ์™„๋ฃŒ๋ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ์ง‘๊ณ„ ํŒŒ์ดํ”„๋ผ์ธ์€ $planCacheStats๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ปฌ๋ ‰์…˜์˜ ๊ณ„ํš ์บ์‹œ ํ•ญ๋ชฉ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

db.orders.aggregate( [
{ $planCacheStats: { } }
] )

์ถœ๋ ฅ:

[
{ // Plan Cache Entry 1
version: '2',
planCacheShapeHash: '478AD696',
planCacheKey: '21AE23AD',
isActive: true,
works: Long("7"),
timeOfCreation: ISODate("2023-05-22T20:33:49.031Z"),
cachedPlan: {
...
},
indexFilterSet: false,
isPinned: false,
estimatedSizeBytes: Long("8194"),
host: 'mongodb1.example.net:27018'
},
{ // Plan Cache Entry 2
version: '2',
planCacheShapeHash: '3D8AFDC6',
planCacheKey: '1C2C4360',
isActive: true,
works: Long("6"),
timeOfCreation: ISODate("2023-05-22T20:33:50.584Z"),
cachedPlan: {
...
},
indexFilterSet: false,
isPinned: false,
estimatedSizeBytes: Long("11547"),
host: 'mongodb1.example.net:27018'
},
{ // Plan Cache Entry 3
version: '2',
planCacheShapeHash: '27285F9B',
planCacheKey: '20BB9404',
isActive: true,
works: Long("1"),
timeOfCreation: ISODate("2023-05-22T20:33:49.051Z"),
cachedPlan: {
...
},
indexFilterSet: false,
isPinned: false,
estimatedSizeBytes: Long("7406"),
host: 'mongodb1.example.net:27018'
},
{ // Plan Cache Entry 4
version: '2',
planCacheShapeHash: '478AD696',
planCacheKey: 'B1435201',
isActive: true,
works: Long("5"),
timeOfCreation: ISODate("2023-05-22T20:33:49.009Z"),
cachedPlan: {
...
},
indexFilterSet: false,
isPinned: false,
estimatedSizeBytes: Long("7415"),
host: 'mongodb1.example.net:27018'
}
],

๊ฒฝ๊ณ 

MongoDB 8.0 ๋ถ€ํ„ฐ ๊ธฐ์กด queryHash ํ•„๋“œ ์˜ ์ด๋ฆ„์ด planCacheShapeHash ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด์ „ MongoDB ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ planCacheShapeHash queryHash ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

planCacheKey๋„ ์ฐธ์กฐํ•˜์„ธ์š”.

ํŠน์ • ์ฟผ๋ฆฌ ํ•ด์‹œ์— ๋Œ€ํ•œ ๊ณ„ํš ์บ์‹œ ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ ค๋ฉด $planCacheStats ๋‹จ๊ณ„ ๋‹ค์Œ์— planCacheKey ํ•„๋“œ ์— $match ๋ฅผ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ์ง‘๊ณ„ ํŒŒ์ดํ”„๋ผ์ธ์€ $planCacheStats์— ์ด์–ด $match ๋‹จ๊ณ„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠน์ • ์ฟผ๋ฆฌ ํ•ด์‹œ์— ๋Œ€ํ•œ ํŠน์ • ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

db.orders.aggregate( [
{ $planCacheStats: { } },
{ $match: { planCacheKey: "B1435201"} }
] )

์ถœ๋ ฅ:

[
{
version: '2',
planCacheShapeHash: '478AD696',
planCacheKey: 'B1435201',
isActive: true,
works: Long("5"),
timeOfCreation: ISODate("2023-05-22T20:33:49.009Z"),
cachedPlan: {
slots: '$$RESULT=s11 env: { s3 = 1684787629009 (NOW), s6 = Nothing, s5 = Nothing, s1 = TimeZoneDatabase(Asia/Kuwait...Etc/UCT) (timeZoneDB), s10 = {"item" : 1, "price" : 1}, s2 = Nothing (SEARCH_META) }',
stages: '[2] nlj inner [] [s4, s7, s8, s9, s10] \n' +
' left \n' +
' [1] cfilter {(exists(s5) && exists(s6))} \n' +
' [1] ixseek s5 s6 s9 s4 s7 s8 [] @"358822b7-c129-47b7-ad7f-40017a51b03c" @"item_1_price_1" true \n' +
' right \n' +
' [2] limit 1 \n' +
' [2] seek s4 s11 s12 s7 s8 s9 s10 none none [] @"358822b7-c129-47b7-ad7f-40017a51b03c" true false \n'
},
indexFilterSet: false,
isPinned: false,
estimatedSizeBytes: Long("7415"),
host: 'mongodb1.example.net:27018'
}
]

๊ฒฝ๊ณ 

MongoDB 8.0 ๋ถ€ํ„ฐ ๊ธฐ์กด queryHash ํ•„๋“œ ์˜ ์ด๋ฆ„์ด planCacheShapeHash ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด์ „ MongoDB ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ planCacheShapeHash queryHash ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

planCacheKey ๋ฐ planCacheShapeHash๋„ ์ฐธ์กฐํ•˜์„ธ์š”.

๋Œ์•„๊ฐ€๊ธฐ

$out