Example #1
0
 public ClusteredIndex(TreeTable Table)
     : base()
 {
     this._Storage      = Table;
     this._Parent       = Table;
     this._Header       = new IndexHeader(Table.Name, -1, -1, -1, 0, 0, Table.BaseTree.Comparer);
     this._IndexColumns = Table.BaseTree.Comparer;
     this._Tree         = Table.BaseTree;
 }
Example #2
0
        /// <summary>
        /// Gets a table, either from memory or disk
        /// </summary>
        /// <param name="Key"></param>
        /// <returns></returns>
        public Table RequestTable(string Key)
        {
            // #DEBUG# //
            this._Host.DebugPrint("TableStore.RequestTable({0})", Key);
            this._Host.DebugDepth++;

            if (this.TableIsInMemory(Key))
            {
                // #DEBUG# //
                this._Host.DebugPrint("TableStore.RequestTable->Table in memory({0})", Key);

                return(this._TableStore[Key]);
            }
            else
            {
                // Get the header //
                TableHeader h = Buffer(Key);
                Table       t;

                // Create the actual table //
                if (h.RootPageID == -1)
                {
                    t = new HeapTable(this._Host, h);

                    // #DEBUG# //
                    this._Host.DebugPrint("TableStore.RequestTable->Table not in memory; buffering table as HEAP ({0})", Key);
                }
                else
                {
                    t = new TreeTable(this._Host, h);

                    // #DEBUG# //
                    this._Host.DebugPrint("TableStore.RequestTable->Table not in memory; buffering table as CLUSTER ({0})", Key);
                }

                // Add to the table store //
                this.PushTable(t);

                // Need to buffer a block of pages and make sure these pages are not in memory

                // Check to see how many pages we can buffer //
                int MaxPages = (int)(this.FreeMemory / h.PageSize);
                int Pages    = Math.Min(h.PageCount, MaxPages);

                // Buffer a block of pages //

                // #DEBUG# //
                this._Host.DebugPrint("TableStore.RequestTable->Buffering a block of pages ({0}); from {1} - {2} of {3}", Key, 0, Pages, h.PageCount);

                foreach (Page p in BufferBlock(h, 0, Pages))
                {
                    PageUID k = new PageUID(Key, p.PageID);
                    if (this._PageStore.ContainsKey(k))
                    {
                        this._PageStore[k] = p;
                    }
                    else
                    {
                        this._PageStore.Add(k, p);
                    }
                }
                this._Host.DebugDepth--;

                return(t);
            }
        }