By default, the Estimate Database Size mechanism uses standard algorithms to calculate the sizes of tablespaces, tables, columns, and indexes and adds them together to provide an indication of the size that the database will require. You can override the algorithm for one or more of these types of objects or include additional objects in the calculation by adding the GetEstimatedSize event handler to the appropriate object in the Profile category and entering a script to calculate its size.
In the following example, we look at extracts of a GetEstimatedSize event handler defined on the Table metaclass to estimate the size of the database by calculating the size of each table as the total size of all its columns plus the total size of all its indexes.
ColSize = C.GetEstimatedSize(message, false), which calls the GetEstimatedSize event handler on the Column metaclass (see Calling the GetEstimatedSize Event Handler on Another Metaclass):
Function %GetEstimatedSize%(obj, ByRef message) ' First compute global database setting variable we will need. ' Get table size and keep column size for future use Dim ColSizes, TblSize, ColSize, C Set ColSizes = CreateObject("Scripting.Dictionary") TblSize = 0 ' May be changed to take into account table definition initial size. for each C in obj.Columns ' Start browsing table columns and use event handler defined on column metaclass (if it exists). ColSize = C.GetEstimatedSize(message, false) ' Store column size in the map for future use in indexes. ColSizes.Add C, ColSize ' Increase the table global size. TblSize = TblSize + ColSize next Dim RawDataSize RawDataSize = BlockSize * int(obj.Number * TblSize / BlockSize) ' At this point, the RawDataSize is the size of table in database.
' Now calculate index sizes. Set up variables to store indexes sizes. Dim X, XMsg, XDataSize XMsg = "" for each X in obj.Indexes XDataSize = 0 ' Browsing index columns and get their size added in XDataSize For each C in X.IndexColumns XDataSize = XDataSize + ColSizes.Item(C.Column) next XDataSize = BlockSize * int(obj.Number * XDataSize / BlockSize) ' Format the display message in order to get size information in output and result list. XMsg = XMsg & CStr(XDataSize) & "|" & X.ObjectID & vbCrLf ' Add the index size to table size. RawDataSize = RawDataSize + XDataSize next
' set the global message to table size and all indexes (separate with carriage return). message = CStr(RawDataSize) & "||" & obj.ShortDescription & vbCrLf & XMsg %GetEstimatedSize% = RawDataSize End Function
Once all the tables have been processed, PowerDesigner calculates and prints the total estimated size of the database.