Skip to content

WFS SortBy only applied within Oracle pages #7463

Open

Description

@JamieIdox

When using Oracle, SortBy is only applied to each page, it is not applied to all the data before paging. Is this deliberate? ie, if I submit a pull request to fix this is it likely to be accepted or rejected?

eg, in the following request note the startIndex and SortBy:

<GetFeature xmlns="http://www.opengis.net/wfs/2.0" service="WFS" version="2.0.0" startIndex="1000" count="1000" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<Query typeNames="wfs:Planning_Application_Polygons" srsName="EPSG:27700" xmlns:wfs="http://mapserver.gis.umn.edu/mapserver">
		<Filter xmlns="http://www.opengis.net/fes/2.0">
			<BBOX>
				<ValueReference>SHAPE</ValueReference>
				<Envelope xmlns="http://www.opengis.net/gml/3.2" srsName="EPSG:27700">
					<lowerCorner>139987.2407923497 -3524.05645833332</lowerCorner>
					<upperCorner>316170.54920765024 157942.01645833335</upperCorner>
				</Envelope>
			</BBOX>
		</Filter>
		<SortBy xmlns="">
			<SortProperty>
				<PropertyName>DATEMODIFIED</PropertyName>
				<SortOrder>DESC</SortOrder>
			</SortProperty>
		</SortBy>
	</Query>
</GetFeature>

This results in the following SQL, note that ROWNUM is included in the inner query:

SELECT * from (
	SELECT atmp.*, ROWNUM rnum from (
		SELECT "REFVAL", "KEYVAL", "DATEMODIFIED", "ADDRESS", "DESCRIPTION", "OBJECTID", rownum, SHAPE 
		FROM PA_V1_6_DCAPPLICATIONS_POLY 
		WHERE  ISPAVISIBLE = 1  AND SDO_FILTER( SHAPE, MDSYS.SDO_GEOMETRY(2003, :srid, NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,3),:ordinates ),'querytype=window') = 'TRUE' 
		ORDER BY "DATEMODIFIED" DESC   
	) atmp 
	where ROWNUM<=2000
) 
where rnum >=1001

What I would like the SQL to be is this, so that the ordering is done before the paging:

SELECT * from (
	SELECT atmp.*, ROWNUM rnum from (
		SELECT btmp.*, ROWNUM from (
			SELECT "REFVAL", "KEYVAL", "DATEMODIFIED", "ADDRESS", "DESCRIPTION", "OBJECTID", SHAPE 
			FROM PA_V1_6_DCAPPLICATIONS_POLY 
			WHERE  ISPAVISIBLE = 1  AND SDO_FILTER( SHAPE, MDSYS.SDO_GEOMETRY(2003, :srid, NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,3),:ordinates ),'querytype=window') = 'TRUE' 
			ORDER BY "DATEMODIFIED" DESC   
		) btmp 
	) atmp 
	where ROWNUM<=2000
) 
where rnum >=1001

Activity

  1. rouault commented on Mar 26, 2026

    @rouault
    Contributor

    Is this deliberate?

    clearly not

  2. JamieIdox commented on Mar 26, 2026

    @JamieIdox
    ContributorAuthor

    I have a suggested solution here: JamieIdox@8c64ac2

    I am happy to do a pull request but I basically have zero knowledge of c and don't have a build environment so I haven't even checked it builds.

  3. geographika commented on Mar 27, 2026

    @geographika
    Member

    @JamieIdox - unfortunately we don't have CI in place to test the Oracle driver, or it would have been fairly straight-forward to add a test for this. Please open a PR anyway, as this is a valid bug, and maybe another MapServer Oracle user will be able to test.

  4. msmitherdc commented on Mar 27, 2026

    @msmitherdc
    Contributor

    @geographika I can build and test a pr

  5. JamieIdox commented on Mar 27, 2026

    @JamieIdox
    ContributorAuthor

    I'm assuming that this error is not due to my changes?

    /home/runner/work/MapServer/MapServer/.github/workflows/start.sh: 25: eval: Syntax error: "(" unexpected (expecting "}")
    Error: Process completed with exit code 2.
    
  6. geographika commented on Mar 28, 2026

    @geographika
    Member

    I'm assuming that this error is not due to my changes?

    /home/runner/work/MapServer/MapServer/.github/workflows/start.sh: 25: eval: Syntax error: "(" unexpected (expecting "}")
    Error: Process completed with exit code 2.
    

    No, this was due to GitHub Actions updating ubuntu-latest from Ubuntu 22.04 to Ubuntu 24.04.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions