Opened 9 years ago

Closed 9 years ago

#3011 closed defect (worksforme)

ST_EstimatedExtent return a incorrect extent value

Reported by: rockyc Owned by: pramsey
Priority: medium Milestone:
Component: postgis Version: 2.1.x
Keywords: ST_EstimatedExtent Cc:

Description

I have a table, and do the following testing.

  1. Execute sql: vacuum analyze st_estimatedextent_test
  1. Execute the sql: select ST_EstimatedExtent('public','st_estimatedextent_test','geom');

Get the result:

BOX(96.6659851074219 -32.3140754699707,129.162185668945 -10.3033857345581)

  1. reinsert a existing row by executing the sql: insert into st_estimatedextent_test select gid,geom from st_estimatedextent_test where gid = 1;
  1. Execute sql vacuum analyze st_estimatedextent_test;
  1. Execute the sql select ST_EstimatedExtent('public','st_estimatedextent_test','geom');

Get the result:

BOX(105.510528564453 -32.3140754699707,129.118179321289 -10.3033857345581)

I think the correct result should be:

BOX(96.6659851074219 -32.3140754699707,129.162185668945 -10.3033857345581), returned in the step 2

Attachments (1)

st_estimatedextent_test.backup (605.1 KB ) - added by rockyc 9 years ago.
the table is backuped by pgadmin.

Download all attachments as: .zip

Change History (7)

by rockyc, 9 years ago

the table is backuped by pgadmin.

comment:1 by pramsey, 9 years ago

As the name indicates, the function is an estimate, generated by taking a sample. It's not necessarily going to be deterministic as you add and change records. How much does the estimate differ from the actual ST_Extent?

in reply to:  1 comment:2 by rockyc, 9 years ago

Replying to pramsey:

As the name indicates, the function is an estimate, generated by taking a sample. It's not necessarily going to be deterministic as you add and change records. How much does the estimate differ from the actual ST_Extent?

Absolutely, we should expect this function to return a estimated value;

But after adding a existing row, I expect the function returns the same value as before because no new geometry is added; at least, I expect the function returns a box which is bigger than the before one, because the box can not be smaller after more rows are added to the table,right? but unfortunately, the returned box is much smaller than the previous one.

comment:3 by pramsey, 9 years ago

The estimate is based on a sample. Changing the rows changes which subset gets picked for the sample, getting a smaller box is not unreasonable.

in reply to:  3 comment:4 by rockyc, 9 years ago

Replying to pramsey:

The estimate is based on a sample. Changing the rows changes which subset gets picked for the sample, getting a smaller box is not unreasonable.

You means, its results is only based on a sample, and can be changed dramatically dependent on the picked sample.

If I understand correctly, does it mean, sometimes, the return box is smaller than the value return from ST_Extent, and sometimes is larger, and also, the difference between ST_EstimatedExtent and ST_Extent can be a big value, right?

If it is true, do you have some guidance on when,where and how to use ST_EstimatedExtent.

Thanks

comment:5 by pramsey, 9 years ago

The estimated bounds can be smaller (will almost always be smaller) than the real bounds (particularly if there are only a few records at the extrema) but can never be larger (since in order to be larger it would have to sample a geometry that wasn't in the full extent calculation, not possible).

in reply to:  5 comment:6 by rockyc, 9 years ago

Resolution: worksforme
Status: newclosed

Replying to pramsey:

The estimated bounds can be smaller (will almost always be smaller) than the real bounds (particularly if there are only a few records at the extrema) but can never be larger (since in order to be larger it would have to sample a geometry that wasn't in the full extent calculation, not possible).

Thanks for your reply.

I totally understand and agree with what you said.

Note: See TracTickets for help on using tickets.