[英]I have a table which has a primary key that is made of three columns. How do I index this table?
Betting houses function like this: every week there are two rounds, and in each round when someone wants to make a ticket he gets a number for that round (first ticket of that round(1), second (2)...). 博彩公司的运作方式是这样的:每周进行两次回合,每回合中有人要出票时,他都会获得该回合的号码(该回合的第一张票(1),第二张票(2)...)。 I have a ticket table of all entered tickets of a betting-house company.
我有一个投注站公司所有已输入票务的票务表。
This table has 30 columns of all the details of each ticket. 该表包含每个票证的所有详细信息的30列。 The primary key is (location, round, number) I explained this number as being the number of the ticket within that round, and the location is the location of the bet-house (a betting company has many bet-houses in different locations).
主键是(位置,回合,号码),我将此数字解释为该回合中的彩票号码,而位置则是下注公司的位置(下注公司在不同位置有很多下注公司) 。 I want to select each ticket one by one, but I do not know how to have some sort of organized way.
我想一张一张地选择每张票,但是我不知道如何有一种有组织的方式。 If the a single column with auto-increment integer type that would be easy.
如果单个列具有自动递增的整数类型,那将很容易。 I just want to some how index this triplet primary key to go through a loop to select each entry incrementally.
我只想了解如何索引此三元组主键以通过循环逐步选择每个条目。 I am using C# to do this?
我正在使用C#来做到这一点?
As you did not provide the real purpose of your task, I can think of 2 situations. 由于您没有提供任务的真正目的,因此我可以想到两种情况。
Firstly, you want to read the table in some smaller batches for processing/evaluation. 首先,您要分批读取表格以进行处理/评估。 In this case you have to make sure the table is immutable and run
SELECT ... ORDER BY number, round, bethouse OFFSET 0 LIMIT 1000
, OFFSET 1000 LIMIT 1000
, OFFSET 2000 LIMIT 1000
and so on until you come to the last row. 在这种情况下,您必须确保表是不可变的,然后运行
SELECT ... ORDER BY number, round, bethouse OFFSET 0 LIMIT 1000
, OFFSET 1000 LIMIT 1000
, OFFSET 2000 LIMIT 1000
等等,直到到达最后一行。
Secondly, you want to process the new incoming rows. 其次,您要处理新的传入行。 In that case there is no way you can solve that with only the multicolumn PK.
在这种情况下,仅使用多列PK是无法解决的。 You have to add a column with an autoincrement value or a date column (ie when the row was created).
您必须添加具有自动增量值的列或日期列(即创建行时)。 Then you order the results by this column and watch for new rows with
WHERE mycolumn > {LastReadValue}
. 然后,您可以按此列对结果进行排序,并使用
WHERE mycolumn > {LastReadValue}
监视新行。
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.