Home > Back-end >  Database implement custom order
Database implement custom order

Time:09-18

Demand is that there is a mall system, need to sort of goods, in the background is free to change a display order goods, I think is in the said goods in the table to add a sequence of fields, but there is a question, if there are tens of thousands of products, change each time order goods may other goods of the order of the fields is not also want to change, so efficiency will certainly be very low, could you tell me how to solve, should can hibernate method is best

CodePudding user response:

First of all, you set the serial number into digital, facilitate indexing and sorting efficiency,
For instance initialization 10000 goods, respectively is 1 ~ 10000 corresponds to the serial number,
Design rules are as follows:
1, the program according to the serial number for the order by and in the form of a list to show to the user, user interface, paging display paging serial number according to the result set to automatically add 1
2, you manage goods in the background, found that need to move, then you have to do is to change the serial number value directly, the serial number can even be set to the decimal, as long as it doesn't affect the sorting result,
3, if entangled with the serial number positive, can be manually triggered the serial number, after you set manually sort, probably including decimal, it can be as long as the execution of the following statement
(presumably)
The update (
The select xuhao, rownum from product order by xuhao
) set xuhao=rownum

Note that the client see serial number and your management side to arrange the serial number is not a concept,

CodePudding user response:

reference 1st floor jiangbo1984 response:
first of all, you set the serial number into digital, facilitate indexing and sorting efficiency,
For instance initialization 10000 goods, respectively is 1 ~ 10000 corresponds to the serial number,
Design rules are as follows:
1, the program according to the serial number for the order by and in the form of a list to show to the user, user interface, paging display paging serial number according to the result set to automatically add 1
2, you manage goods in the background, found that need to move, then you have to do is to change the serial number value directly, the serial number can even be set to the decimal, as long as it doesn't affect the sorting result,
3, if entangled with the serial number positive, can be manually triggered the serial number, after you set manually sort, probably including decimal, it can be as long as the execution of the following statement
(presumably)
The update (
The select xuhao, rownum from product order by xuhao
) set xuhao=rownum

Note that the client see serial number and your management side to arrange the serial number is not a concept,

If have three goods, the serial number is respectively is 1, 2, 3, now need to change the commodity serial number of the serial number for the 3 to 1, and all will affect the original goods, that is to say, I only change a sort of goods, will put the other data, it will affect performance, I just want to how to solve this problem

CodePudding user response:

123 - & gt; 312 this insert how to solve? The status of the move to back a 12? If a small amount of data is much good if the data in the for loop will very consumption performance??????????? No solution?

CodePudding user response:

The demand of simple design, add a sort field, this field to save the time stamp, to the millisecond, as that can be sorted by the column flashback, when you take a goods placed at the top, you can insert the current time stamp is ok, if you want to insert a line a before, during and after the goods, the goods right away it is ok to add and subtract a timestamp,

CodePudding user response:

CodePudding user response:

reference wjy550823795 reply: 3/f
123 - & gt; 312 this insert how to solve? The status of the move to back a 12? If a small amount of data is much good if the data in the for loop will very consumption performance??????????? No solution?
recommended linked series, so that will be of high efficiency

CodePudding user response:

Don't know if my understanding is correct. Do you want the original sequence, random moving an element to a specified location. The query SQL unchanged, and returns a list of elements you want to move to the location on the list.

CodePudding user response:

Under normal circumstances, if is the requirement of absolute order, won't have too big amount of data, if the data quantity is large, will not require absolute order,
Google, baidu and taobao search is absolutely will not ask what information must be in which position,

If you still want to the order of the absolute, and the data quantity is big, do not want to reorder every time modify, then suggest don't use the mysql database, such as their own implementation of a red-black tree structure, guarantee the performance of leverage,

CodePudding user response:

refer to the second floor of ling2 han2 11 reply:
if there are three goods, the serial number is respectively is 1, 2, 3, now need to change the commodity serial number of the serial number for the 3 to 1, and all will affect the original goods, that is to say, I just change a sort of goods, will put the other data, it will affect performance, I just want to how to solve this problem


According to what you say, I think in general is to ensure that the order of a few pages of the export goods before, actually doesn't make sense in the behind,

For example: make sure the goods have priority level 20, other are all the same, when a change is as long as there is priority level changes of article 20,

CodePudding user response:

It's funny, didn't add the sort field, don't, don't sort the background query?

Some rigid thinking of the building Lord, you add the field's main function is to arrange the special goods, or to arrange all the goods?
Arrange all the goods, why not use id to sort?

What you mean? Is to say, you add a sort field, the field, only that the background set manually order record, the rest of the records, in accordance with the default collation,

How to achieve this goal?
New fields, the default set to 0, the background change order, all sorted value is greater than zero, that is to say, this order is from big to small, backwards, or, you query, according to the priority field flashbacks rank the result is ok,
As for artificial changes that a few data, sequence, adjust the size of the numerical, or programming automatically update these records, or, artificial change order value,

  • Related