View creation/drop performance degrades with the number of views due to view catalog (ViewsForDatabase) copying

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: 7.0.0, 8.0.0, 8.2.0, 9.0.0-rc0, 8.3.0
    • Component/s: Catalog, Performance
    • None
    • Catalog and Routing
    • 2
    • 馃煢 Shard Catalog
    • None
    • None
    • None
    • None
    • None
    • None

      The list of views of each DB is backed by the ViewsForDatabase data structure, which does not have copy-on-write semantics.

      When creating or dropping a view, this data structure is copied is several places, so performance degrades with the number of views:

      • Creating/dropping a view has O(N) complexity where N=number of existing views.
      • Creating/dropping N views has O(N^2) complexity

      This could be solved by implementing copy-on-write semantics or some similar kind of incremental update strategy for ViewsForDtabase.

      Practical impact

      In practice performance degrades noticeably when a DB has 1000s of views or viewful timeseries collections.

      With N=15000 views, on a 3 node RS, optimized build, m7g.2xlarge VM w/ gp3 storage):

      • Creating 2000 views --> 35 seconds (18ms per view)
      • Drop 2000 views --> 75 seconds (38ms per view)

      Frame graphs for create view

      In those flame graphs most of the time spent in the commit of the WUOW (e.g. CollectionCatalog::write) and CollectionCatalog::createView copying and destroying the ViewsForDatabase data structure.

      Replica set primary:

      Replica set secondary:

      Frame graphs for drop view

      聽Those frame graphs show the known performance issue in SERVER-78615聽aside from the same performance impact of copying/destroying聽ViewsForDatabase:

      Replica set primary:

      Replica set secondary:

        1. perf_dropview_secondary.svg
          272 kB
        2. perf_dropview_primary.svg
          492 kB
        3. perf_createview_secondary.svg
          503 kB
        4. perf_createview_primary.svg
          651 kB
        5. image-2026-04-23-08-28-01-799.png
          image-2026-04-23-08-28-01-799.png
          310 kB
        6. image-2026-04-23-08-27-47-236.png
          image-2026-04-23-08-27-47-236.png
          352 kB
        7. image-2026-04-23-08-27-36-110.png
          image-2026-04-23-08-27-36-110.png
          287 kB
        8. image-2026-04-23-08-26-51-032.png
          image-2026-04-23-08-26-51-032.png
          427 kB

            Assignee:
            Unassigned
            Reporter:
            Joan Bruguera Mic贸
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: