Hi Vince
I found this post mostly matching to my issue. I'm using ArcGIS Version 10.2.2.
In my GP script, I deleted all old features from a FC using arcpy.DeleteFeatures_management.
and Inserted new features by using arcpy.da.insertcursor, record inserted in the correct order, I can see from auto generated object ids.
But on opening attribute table in ArcMAP or preview in ArcCatelog the table don't show records sorted on Object ID. I tried to rebuild indexes, set spatial index on FC using owner. It did not help
If I use CopyFeatures, FeatureClassToFeatureClass, Append management tools, features show up correctly sorted on ObjectID. In my GP scenario I'm not the owner of dataset/feature class. I'm working with another user having privilege to insert update delete records.
What's the difference. How I can see data on sorted order?
Thanks and Regards
Lalit Arora
Once you start using DELETE, the database is well within rights to place rows in any page it deems appropriate (each table has its own "high water mark" of previously allocated extents).
If you actually TRUNCATE the table instead of DELETE, then the rows would likely be placed in the order you inserted them (since the high water mark is cleared, and new blocks are being allocated)
It's important to know that the database is not obligated to return rows in any particular order unless an ORDER BY clause is used. Also, once the spatial extent reaches a quarter of the overall extent, spatial queries are likely to return features in spatial index order.
- V
Thanks Vince for prompt reply.
I'm not deleting table. GP Script user is not the owner of the table. So it can not create or delete schema. I'm just deleting existing features and inserting new one in exiting schema.
DeleteFeatures_management - deleting rows
arcpy.da.insertcursor - inserting rows
If I use CopyFeatures, FeatureClassToFeatureClass, Append management tools, output features show up correctly sorted on ObjectID. I can't use these tools in present case.(limitation in my scenario)
If same feature data set (i.e. same spatial extent) show up differently created by above two ways.
What's missing to show it up correctly?
In database terms, DELETE is something that happens to rows. Table deletion is referred to with the directive DROP. If you did DROP the table it wouldn't be an issue, since TRUNCATE is a lot like dropping the table then recreating it, without the mess of having to repopulate the database catalog and recreate all the indexes.
I did state that rows inserted into blocks allocated to a table's free list would produce random ordering. I didn't go into it the why, but there's an entire domain of Computer Science to choose how to most efficiently reallocate an existing list of storage, and the algorithms most likely to make most efficient use of the space are also least likely to result in features physically stored in insertion order.
You should use the Truncate Table tool I referred to in my answer, instead of Delete Features, but if you aren't replacing contents as the table owner, then you'll need to research the proper way to construct a stored procedure to permit that to happen (it's similar, but different in Oracle and SQL-Server). Depending on the geometry storage model, you may need to manually TRUNCATE ancillary tables as well.
- V
Thanks Vince
I got your explanation regarding physical storage of data on disk and completely agree to it.
Only limitation I'm not the owner of data set. So I also cant use Truncate tool.
If i was owner, I would have used FeatureClassToFeatureClass tool, which deleted old and create new one in one statement. I'll explore stored procedure option as you told.
One doubt still I have. rows inserted into a feature dataset with Append_management tool shows correctly sorted data based on ObjectId. Its just add more features in to existing dataset without creating it again. Internally It should also have created a cursor to push new data and same physical allocation algorithm applied to this as well. How differently it worked?
Best practice-wise, if you're replacing the contents of a table, you should be doing so as the owner.
Only the owner has the ability to:
Even if you accomplish the TRUNCATE without being the owner, all the others are REQUIRED for adequate performance; you're setting yourself up for a 7-ball juggling contest while placing one arm in a sling and belting yourself to a unicycle.
II don't understand your description of the data flow, but if features are allocated in sequential order, it's likely because the free list was empty or exhausted by bulk insertion.
- V
Thanks Vince.