Skip to content

Commit

Permalink
Merge pull request #2851 from manticoresoftware/scroll_sorting_fix
Browse files Browse the repository at this point in the history
fixed option scroll vs sorting by single attribute
  • Loading branch information
glookka authored Dec 13, 2024
2 parents f2f57e4 + 07a6c94 commit 4abb056
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/sorterscroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,12 @@ static void AddScrollFilter ( CSphQuery & tQuery )
if ( tFirst.m_eType==SPH_ATTR_STRINGPTR )
return;

bool bOnlyId = tQuery.m_tScrollSettings.m_dAttrs.GetLength()==1;

CSphFilterSettings & tFilter = tQuery.m_dFilters.Add();
tFilter.m_eType = tFirst.m_eType==SPH_ATTR_FLOAT ? SPH_FILTER_FLOATRANGE : SPH_FILTER_RANGE;
tFilter.m_sAttrName = tFirst.m_sSortAttr=="weight()" ? "@weight" : tFirst.m_sSortAttr;
tFilter.m_bHasEqualMin = tFilter.m_bHasEqualMax = !bOnlyId;

if ( tFirst.m_eType==SPH_ATTR_FLOAT )
{
Expand Down
2 changes: 1 addition & 1 deletion test/test_307/model.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a:1:{i:0;a:11:{i:0;a:2:{s:8:"sphinxql";s:30:"create table t1(f text, a int)";s:14:"total_affected";i:0;}i:1;a:2:{s:8:"sphinxql";s:80:"insert into t1 values(1, 'a', 1),(2, 'b', 1),(3, 'a', 2),(4, 'a', 3),(5, 'a', 5)";s:14:"total_affected";i:5;}i:2;a:2:{s:8:"sphinxql";s:30:"create table t2(f text, a int)";s:14:"total_affected";i:0;}i:3;a:2:{s:8:"sphinxql";s:81:"insert into t2 values(6, 'a', 1),(7, 'b', 1),(8, 'a', 2),(9, 'a', 3),(10, 'a', 5)";s:14:"total_affected";i:5;}i:4;a:2:{s:8:"sphinxql";s:91:"create table d type='distributed' agent='<AGENT0_ADDRESS/>:t1' agent='<AGENT0_ADDRESS/>:t2'";s:14:"total_affected";i:0;}i:5;a:3:{s:8:"sphinxql";s:47:"select * from d order by a asc, id desc limit 5";s:10:"total_rows";i:5;s:4:"rows";a:5:{i:0;a:3:{s:2:"id";s:1:"7";s:1:"f";s:1:"b";s:1:"a";s:1:"1";}i:1;a:3:{s:2:"id";s:1:"6";s:1:"f";s:1:"a";s:1:"a";s:1:"1";}i:2;a:3:{s:2:"id";s:1:"2";s:1:"f";s:1:"b";s:1:"a";s:1:"1";}i:3;a:3:{s:2:"id";s:1:"1";s:1:"f";s:1:"a";s:1:"a";s:1:"1";}i:4;a:3:{s:2:"id";s:1:"8";s:1:"f";s:1:"a";s:1:"a";s:1:"2";}}}i:6;a:3:{s:8:"sphinxql";s:11:"show scroll";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:1:{s:12:"scroll_token";s:192:"eyJvcmRlcl9ieV9zdHIiOiJhIGFzYywgaWQgZGVzYyIsIm9yZGVyX2J5IjpbeyJhdHRyIjoiYSIsImRlc2MiOmZhbHNlLCJ2YWx1ZSI6MiwidHlwZSI6ImludCJ9LHsiYXR0ciI6ImlkIiwiZGVzYyI6dHJ1ZSwidmFsdWUiOjgsInR5cGUiOiJpbnQifV19";}}}i:7;a:3:{s:8:"sphinxql";s:256:"select * from d order by a asc, id desc limit 5 option scroll='eyJvcmRlcl9ieV9zdHIiOiJhIGFzYywgaWQgZGVzYyIsIm9yZGVyX2J5IjpbeyJhdHRyIjoiYSIsImRlc2MiOmZhbHNlLCJ2YWx1ZSI6MiwidHlwZSI6ImludCJ9LHsiYXR0ciI6ImlkIiwiZGVzYyI6dHJ1ZSwidmFsdWUiOjgsInR5cGUiOiJpbnQifV19'";s:10:"total_rows";i:5;s:4:"rows";a:5:{i:0;a:3:{s:2:"id";s:1:"3";s:1:"f";s:1:"a";s:1:"a";s:1:"2";}i:1;a:3:{s:2:"id";s:1:"9";s:1:"f";s:1:"a";s:1:"a";s:1:"3";}i:2;a:3:{s:2:"id";s:1:"4";s:1:"f";s:1:"a";s:1:"a";s:1:"3";}i:3;a:3:{s:2:"id";s:2:"10";s:1:"f";s:1:"a";s:1:"a";s:1:"5";}i:4;a:3:{s:2:"id";s:1:"5";s:1:"f";s:1:"a";s:1:"a";s:1:"5";}}}i:8;a:2:{s:8:"sphinxql";s:12:"drop table d";s:14:"total_affected";i:0;}i:9;a:2:{s:8:"sphinxql";s:13:"drop table t1";s:14:"total_affected";i:0;}i:10;a:2:{s:8:"sphinxql";s:13:"drop table t2";s:14:"total_affected";i:0;}}}
a:1:{i:0;a:16:{i:0;a:2:{s:8:"sphinxql";s:30:"create table t1(f text, a int)";s:14:"total_affected";i:0;}i:1;a:2:{s:8:"sphinxql";s:80:"insert into t1 values(1, 'a', 1),(2, 'b', 1),(3, 'a', 2),(4, 'a', 3),(5, 'a', 5)";s:14:"total_affected";i:5;}i:2;a:2:{s:8:"sphinxql";s:30:"create table t2(f text, a int)";s:14:"total_affected";i:0;}i:3;a:2:{s:8:"sphinxql";s:81:"insert into t2 values(6, 'a', 1),(7, 'b', 1),(8, 'a', 2),(9, 'a', 3),(10, 'a', 5)";s:14:"total_affected";i:5;}i:4;a:2:{s:8:"sphinxql";s:91:"create table d type='distributed' agent='<AGENT0_ADDRESS/>:t1' agent='<AGENT0_ADDRESS/>:t2'";s:14:"total_affected";i:0;}i:5;a:3:{s:8:"sphinxql";s:47:"select * from d order by a asc, id desc limit 5";s:10:"total_rows";i:5;s:4:"rows";a:5:{i:0;a:3:{s:2:"id";s:1:"7";s:1:"f";s:1:"b";s:1:"a";s:1:"1";}i:1;a:3:{s:2:"id";s:1:"6";s:1:"f";s:1:"a";s:1:"a";s:1:"1";}i:2;a:3:{s:2:"id";s:1:"2";s:1:"f";s:1:"b";s:1:"a";s:1:"1";}i:3;a:3:{s:2:"id";s:1:"1";s:1:"f";s:1:"a";s:1:"a";s:1:"1";}i:4;a:3:{s:2:"id";s:1:"8";s:1:"f";s:1:"a";s:1:"a";s:1:"2";}}}i:6;a:3:{s:8:"sphinxql";s:11:"show scroll";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:1:{s:12:"scroll_token";s:192:"eyJvcmRlcl9ieV9zdHIiOiJhIGFzYywgaWQgZGVzYyIsIm9yZGVyX2J5IjpbeyJhdHRyIjoiYSIsImRlc2MiOmZhbHNlLCJ2YWx1ZSI6MiwidHlwZSI6ImludCJ9LHsiYXR0ciI6ImlkIiwiZGVzYyI6dHJ1ZSwidmFsdWUiOjgsInR5cGUiOiJpbnQifV19";}}}i:7;a:3:{s:8:"sphinxql";s:256:"select * from d order by a asc, id desc limit 5 option scroll='eyJvcmRlcl9ieV9zdHIiOiJhIGFzYywgaWQgZGVzYyIsIm9yZGVyX2J5IjpbeyJhdHRyIjoiYSIsImRlc2MiOmZhbHNlLCJ2YWx1ZSI6MiwidHlwZSI6ImludCJ9LHsiYXR0ciI6ImlkIiwiZGVzYyI6dHJ1ZSwidmFsdWUiOjgsInR5cGUiOiJpbnQifV19'";s:10:"total_rows";i:5;s:4:"rows";a:5:{i:0;a:3:{s:2:"id";s:1:"3";s:1:"f";s:1:"a";s:1:"a";s:1:"2";}i:1;a:3:{s:2:"id";s:1:"9";s:1:"f";s:1:"a";s:1:"a";s:1:"3";}i:2;a:3:{s:2:"id";s:1:"4";s:1:"f";s:1:"a";s:1:"a";s:1:"3";}i:3;a:3:{s:2:"id";s:2:"10";s:1:"f";s:1:"a";s:1:"a";s:1:"5";}i:4;a:3:{s:2:"id";s:1:"5";s:1:"f";s:1:"a";s:1:"a";s:1:"5";}}}i:8;a:3:{s:8:"sphinxql";s:40:"select * from d order by id desc limit 2";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:3:{s:2:"id";s:2:"10";s:1:"f";s:1:"a";s:1:"a";s:1:"5";}i:1;a:3:{s:2:"id";s:1:"9";s:1:"f";s:1:"a";s:1:"a";s:1:"3";}}}i:9;a:3:{s:8:"sphinxql";s:11:"show scroll";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:1:{s:12:"scroll_token";s:120:"eyJvcmRlcl9ieV9zdHIiOiJpZCBkZXNjIiwib3JkZXJfYnkiOlt7ImF0dHIiOiJpZCIsImRlc2MiOnRydWUsInZhbHVlIjo5LCJ0eXBlIjoiaW50In1dfQ==";}}}i:10;a:3:{s:8:"sphinxql";s:160:"select * from d limit 2 option scroll='eyJvcmRlcl9ieV9zdHIiOiJpZCBkZXNjIiwib3JkZXJfYnkiOlt7ImF0dHIiOiJpZCIsImRlc2MiOnRydWUsInZhbHVlIjo5LCJ0eXBlIjoiaW50In1dfQ=='";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:3:{s:2:"id";s:1:"8";s:1:"f";s:1:"a";s:1:"a";s:1:"2";}i:1;a:3:{s:2:"id";s:1:"7";s:1:"f";s:1:"b";s:1:"a";s:1:"1";}}}i:11;a:3:{s:8:"sphinxql";s:11:"show scroll";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:1:{s:12:"scroll_token";s:120:"eyJvcmRlcl9ieV9zdHIiOiJpZCBkZXNjIiwib3JkZXJfYnkiOlt7ImF0dHIiOiJpZCIsImRlc2MiOnRydWUsInZhbHVlIjo3LCJ0eXBlIjoiaW50In1dfQ==";}}}i:12;a:3:{s:8:"sphinxql";s:160:"select * from d limit 2 option scroll='eyJvcmRlcl9ieV9zdHIiOiJpZCBkZXNjIiwib3JkZXJfYnkiOlt7ImF0dHIiOiJpZCIsImRlc2MiOnRydWUsInZhbHVlIjo3LCJ0eXBlIjoiaW50In1dfQ=='";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:3:{s:2:"id";s:1:"6";s:1:"f";s:1:"a";s:1:"a";s:1:"1";}i:1;a:3:{s:2:"id";s:1:"5";s:1:"f";s:1:"a";s:1:"a";s:1:"5";}}}i:13;a:2:{s:8:"sphinxql";s:12:"drop table d";s:14:"total_affected";i:0;}i:14;a:2:{s:8:"sphinxql";s:13:"drop table t1";s:14:"total_affected";i:0;}i:15;a:2:{s:8:"sphinxql";s:13:"drop table t2";s:14:"total_affected";i:0;}}}
6 changes: 6 additions & 0 deletions test/test_307/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ select * from d order by a asc, id desc limit 5;
show scroll;
select * from d order by a asc, id desc limit 5 option scroll='eyJvcmRlcl9ieV9zdHIiOiJhIGFzYywgaWQgZGVzYyIsIm9yZGVyX2J5IjpbeyJhdHRyIjoiYSIsImRlc2MiOmZhbHNlLCJ2YWx1ZSI6MiwidHlwZSI6ImludCJ9LHsiYXR0ciI6ImlkIiwiZGVzYyI6dHJ1ZSwidmFsdWUiOjgsInR5cGUiOiJpbnQifV19';

select * from d order by id desc limit 2;
show scroll;
select * from d limit 2 option scroll='eyJvcmRlcl9ieV9zdHIiOiJpZCBkZXNjIiwib3JkZXJfYnkiOlt7ImF0dHIiOiJpZCIsImRlc2MiOnRydWUsInZhbHVlIjo5LCJ0eXBlIjoiaW50In1dfQ==';
show scroll;
select * from d limit 2 option scroll='eyJvcmRlcl9ieV9zdHIiOiJpZCBkZXNjIiwib3JkZXJfYnkiOlt7ImF0dHIiOiJpZCIsImRlc2MiOnRydWUsInZhbHVlIjo3LCJ0eXBlIjoiaW50In1dfQ==';

drop table d;
drop table t1;
drop table t2;
Expand Down

0 comments on commit 4abb056

Please sign in to comment.