Table sort

Table sort

tomi_kosunen
Not applicable
16 Views
5 Replies
Message 1 of 6

Table sort

tomi_kosunen
Not applicable

[ FlexSim 20.2.3 ]

Hi

I have Table that has ~88000 rows and 2 columns (both numeric). I have to sort the table by a column 1 (on model reset). The sort takes about one minute to make. Is there a way to make it any faster?

Used command: myTable.sort(1);


0 Likes
Accepted solutions (1)
17 Views
5 Replies
Replies (5)
Message 2 of 6

lars_jacobsen_ScandiSim
Advocate
Advocate

Have you tried to use Table.addIndex and Table.getRowByKey instead of sorting your table? It requires that it is a bundle table.

0 Likes
Message 3 of 6

MBJEBZSRG
Advocate
Advocate
Accepted solution

Hi Tomi,

As Lars said, addIndex() is perfect for that task, but remember that it only works on Bundle Data tables. An alternative is to use a query with a ORDER BY Column1 ASC/DESC, Column2 ASC/DESC. This is also pretty fast even on non indexed / non bundle tables.

I did a small test with a table with 88000 rows and two columns.

  • Using Table.Sort() took 158,76 seconds
  • Using a query and dumping the sorted result in another table took 0,77 seconds
  • Converting the table to bundled data and indexing both columns ordered and then using Table.Sort took 0.04 seconds.
  • Using a query on the bundled table took 0,35 seconds.
Message 4 of 6

tomi_kosunen
Not applicable

Perfect. What would be the sql syntax, if the Column header has space in its name, like

"Sort Order"?

This doesn't work: string queryStrings = "SELECT * FROM OrdetTable ORDER BY 'Sort Order' ASC";

0 Likes
Message 5 of 6

lars_jacobsen_ScandiSim
Advocate
Advocate

You need to use square brackets [] when you have names with spaces. "SELECT * FROM OrderTable ORDER BY [Sort Order] ASC"

https://docs.flexsim.com/en/21.0/Reference/DeveloperAdvancedUser/SQLQueries

Message 6 of 6

Ben_WilsonADSK
Community Manager
Community Manager

Hi @tomi.kosunen, was martin.j's answer helpful? If so, please click the red "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes