1.. _rfc-13:
2
3================================================================================
4RFC 13: Improved Feature Insertion/Update/Delete Performance in Batch Mode
5================================================================================
6
7::
8
9   Author: Konstantin Baumann
10
11   Contact: konstantin.baumann@hpi.uni-potsdam.de
12
13   Status: Withdrawn
14
15*Withdrawn*
16
17I have withdrawn this RFC based on some comments from
18`Frank <http://lists.maptools.org/pipermail/gdal-dev/2007-May/013132.html>`__
19and
20`Tamas <http://lists.maptools.org/pipermail/gdal-dev/2007-May/013130.html>`__
21on GDAL-dev.
22
23*Summary*
24
25Some OGR drivers can dramatically increase the speed of and optimize the
26insertion, update, and deletion of a set of features, if the driver
27knows, that there is a whole set of features that should/could be
28inserted, updated, or deleted at once (instead of just one by one).
29
30*CreateFeatures()*
31
32The following new virtual method is added to the OGRLayer class, with an
33analogous C function:
34
35::
36
37   virtual OGRErr CreateFeatures( OGRFeature** papoFeatures, int iFeatureCount );
38
39A default implementation is given as below:
40
41::
42
43   OGRErr OGRLayer::CreateFeatures(
44       OGRFeature **papoFeatures,
45       int iFeatureCount
46   ) {
47       for(int i = 0; i < iFeatureCount; ++i) {
48           OGRErr error = CreateFeature( papoFeatures[i] );
49           if( error != OGRERR_NONE ) return error;
50       }
51       return OGRERR_NONE;
52   }
53
54This triggers the old behavior of an unoptimized insertion.
55
56Individual drivers can override the default implementation and can
57implement an optimized algorithm for inserting a set of features.
58
59*SetFeatures()*
60
61The following new virtual method is added to the OGRLayer class, with an
62analogous C function:
63
64::
65
66   virtual OGRErr SetFeatures( OGRFeature** papoFeatures, int iFeatureCount );
67
68A default implementation is given as below:
69
70::
71
72   OGRErr OGRLayer::SetFeatures(
73       OGRFeature **papoFeatures,
74       int iFeatureCount
75   ) {
76       for(int i = 0; i < iFeatureCount; ++i) {
77           OGRErr error = SetFeature( papoFeatures[i] );
78           if( error != OGRERR_NONE ) return error;
79       }
80       return OGRERR_NONE;
81   }
82
83This triggers the old behavior of an unoptimized update.
84
85Individual drivers can override the default implementation and can
86implement an optimized algorithm for updating a set of features.
87
88*DeleteFeatures()*
89
90The following new virtual method is added to the OGRLayer class, with an
91analogous C function:
92
93::
94
95   virtual OGRErr DeleteFeatures( long *panFIDs, int iFIDCount );
96
97A default implementation is given as below:
98
99::
100
101   OGRErr OGRLayer::DeleteFeatures(
102       long *panFIDs,
103       int iFIDCount
104   ) {
105       for(int i = 0; i < iFIDCount; ++i) {
106           OGRErr error = DeleteFeature( panFIDs[i] );
107           if( error != OGRERR_NONE ) return error;
108       }
109       return OGRERR_NONE;
110   }
111
112This triggers the old behavior of an unoptimized deletion.
113
114Individual drivers can override the default implementation and can
115implement an optimized algorithm for deleting a set of features.
116
117*C API functions*
118
119The following C functions are added:
120
121::
122
123   OGRErr OGR_L_CreateFeatures( OGRFeature** papoFeatures, int iFeatureCount );
124   OGRErr OGR_L_SetFeatures( OGRFeature** papoFeatures, int iFeatureCount );
125   OGRErr OGR_L_DeleteFeatures( long* panFIDs, int iFIDCount );
126
127However, there are some issues with adding plain C arrays to the public
128OGR interface due to the SWIG based wrapping, see for example `GDAL-Dev
129Mail from
130Tamas <http://lists.maptools.org/pipermail/gdal-dev/2007-May/013092.html>`__...
131
132*Additional Notes*
133
134Based in this new interface functions, I was able to increase the
135insertion speed of features in the MySQL driver from 40 per second to up
136to 800-2000 per second. I think other drivers can benefit from this
137change, too.
138
139See also ticket #1633.
140
141*Implementation Plan*
142
143A patch for the describe additions can be trivially provided.
144
145I can provide another patch based on this interface which contains the
146optimized implementation for the MySQL driver.
147
148*History*
149
15014-May-2007: initial version created
151
15215-May-2007: SetFeatures() added
153
15416-May-2007: DeleteFeatures() added
155
15617-May-2007: C API functions added; SWIG wrapping issues mentioned
157
15823-May-2007: Withdrawn due some concerns on GDAL-dev
159