Question Meenakshi Muthu · May 13, 2024

Difference between %KillExtent and %DeleteExtent

Can any one tell me the difference between %KillExtent and %DeleteExtent with example

Comments

Robert Cemper · May 13, 2024

it's best described in docs

classmethod %DeleteExtent(concurrency As %Integer = -1, ByRef deletecount, ByRef instancecount, pInitializeExtent As %Integer = 1, Output errorLog As %Status) as %Status

Delete all instances of this class from its extent. On exit instancecount contains the original number of instances while deletecount contains the number of instances actually deleted.

Internally, %DeleteExtent() iterates over the set of instances in the collection and invokes the %Delete() method.
Refer to Object Concurrency Options for more details on the optional concurrency argument.
The option pInitializeExtent argument allows the user to override the default behavior of calling %KillExtent() when all instances are successfully deleted. %KillExtent() is called by default when the extent is empty so that empty globals can be killed. If %KillExtent() is not called then some empty globals can remain as well as the ID counter if it exists. The default value for pInitializeExtent is 1. Unless the caller specifies a false value for pInitializeExtent the globals used by the extent will be killed. If the process' GlobalKillDisabled flag is enabled and not the default of false the process' GlobalKillDisabled flag will be changed temporarily to false to allow the operation to complete without a possible error. In some cases, the globals used by the extent are not used exclusively by the extent. In those cases it is possible that some globals will still be defined even when pInitializeExtent is true. By default this call to %KillExtent() will not delete default stream storage global, but if you pass '2' in pInitializeExtent and if the entire extent was deleted we will call %KillExtent passing the 'killstreams' flag to ask it to remove kill the default storage global.

Returns a %Status value indicating success or failure.

classmethod %KillExtent(pDirect As %Integer = 1, killstreams As %Boolean = 0) as %Status

%KillExtent performs a physical kill of the extent. No constraints are enforced. This method should not be used in place of %DeleteExtent. Only physical storage occupied by this extent will be killed. If this extent is a subextent of another class then no data is killed. Indexes that originate with this extent will be killed. %KillExtent will be called on any subextents and on any child extents (the extent of the type class of a relationship whose cardinality = children is a 'child' extent) of this extent.
This method is not meant for production applications. It is meant to be a development utility to quickly clear extent physical data. Also this will not remove stream data associated with these instances.
If killstreams is true (default is false) it will also kill the default stream storage global.

0
Robert Cemper  May 16, 2024 to Meenakshi Muthu

more drastic: KILL  does an ObjectScript Kill on all related Globals. Quick and Fast
DELETE loops on subscripts and mimics a SQL DELETE row by row and has definitely more overhead
 

0
Dan Pasco  May 27, 2024 to Meenakshi Muthu

The simplest answer is that %KillExtent performs a physical delete of the extent (data and indexes) while %DeleteExtent performs a logical delete. The physical delete does not enforce any constraints and does not invoke referential actions. The logical delete does enforce all constraints and  performs referential actions.

0
Lana watson · May 28, 2024

Hello there, it is an interesting discussion.

Thanks for the detailed explanations. It is helpful to know that KillExtent is faster but skips triggers, while DeleteExtent is more comprehensive, ensuring referential integrity and triggering deletes. Have you ever come across any specific scenarios; where one is clearly preferable over the other?

0
Dan Pasco  May 28, 2024 to Lana watson

%KillExtent should not be used in production except in very controlled circumstances. It was meant for use in a development environment. It's only advantage is that it is fast.

0