question

Tomi Kosunen avatar image
0 Likes"
Tomi Kosunen asked Ben Wilson commented

Table sort

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);


FlexSim 20.2.3
flexsim 20.2.3table sort
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Lars Jacobsen avatar image Lars Jacobsen commented ·

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 0 ·
Ben Wilson avatar image Ben Wilson ♦♦ commented ·

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 0 ·

1 Answer

martin.j avatar image
1 Like"
martin.j answered Lars Jacobsen commented

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.
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Lars Jacobsen avatar image Lars Jacobsen commented ·

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

1 Like 1 ·
Tomi Kosunen avatar image Tomi Kosunen commented ·

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 0 ·