如何有效地获取日期范围内的分页查询结果(How to efficiently get paged query results for a date range)
刚开始使用NoSql,特别是DynamodB,我被问到以下问题:
有一个有大量行的现有表,其中的字段如下所示:
RecordId (Guid = partition key) RecordType (Guid = sort key) UserId (Guid) CreationDateTime ... and some other attributes ...
还有一个GSI(比如GSI1):
UserId = partition key RecordType = sort key
某些用户使用相同的RecordType生成大量行(可能每天数百或数千),因此此索引通常具有大量具有相同UserId + RecordType的行。
我希望能够有效地执行分页查询以查找与特定UserId + RecordType匹配的结果,并在一定范围的日期内具有CreationDateTime。
达到此目的的最佳方式是什么?
有人建议我可以用partitionKey = Userid和Sort key = CreationDateTime创建第二个GSI(比如GSI2)。 这个想法是,这将是找到所需日期范围内UserId + RecordType的第一行的有效方法,然后这将用作在GSI1中搜索的起点(PaginationToken)。 只有在GSI1中具有重复键的行按创建顺序存储时才能使用。
这有意义吗? 如果不是,那么更好的方法是什么?
Just starting out with NoSql in general and DynamodB in particular, and I've been asked the following question:
There is an existing table with a large number of rows with fields something like:
RecordId (Guid = partition key) RecordType (Guid = sort key) UserId (Guid) CreationDateTime ... and some other attributes ...
There is also a GSI (say GSI1) with:
UserId = partition key RecordType = sort key
Some users generate a large number of rows with the same RecordType (maybe hundreds or thousands per day), so this index typically has a large number of rows with the same UserId+RecordType.
I want to be able to efficiently execute a paged query for results that match a specific UserId+RecordType, and have a CreationDateTime within a range of dates.
What's the best way to achieve this?
It's been suggested to me that I can create a second GSI (say GSI2) with partitionKey = Userid and Sort key = CreationDateTime. The idea being that this would be an efficient way to find the first row for UserId+RecordType that is in the required date range, and that then this would be used as a starting point (PaginationToken) for searching in GSI1. Which would only work if the rows in GSI1 with a duplicate key are stored in order of creation.
Does this make sense? And if not, what would be a better approach?
原文:https://stackoverflow.com/questions/47657590
最满意答案
strcat()需要一个以null结尾的字符串作为输入。 所以strcat(token和&current)将开始读取当前地址并继续运行直到找到null。 只是偶然,你当前在内存中的内容是“\ 001”,所以每次你执行strcat时它都会将所有内容复制到令牌中。
你应该做char current [] =“\ 0 \ 0”,然后用current [0] = chs [++ pos]赋值。 那样,current将始终具有null终止。
strcat() needs a null-terminated string as it's input. so strcat(token, ¤t) will start reading at the address of current and keep going until it finds a null. Just by chance, what you had in memory after current was "\001", so each time you did strcat it copied all that into token.
You should do char current[] = "\0\0" and then assign it with current[0] = chs[++pos]. That way current will always have that null termination.
相关问答
更多-
scp001真的存在吗,之前有个人和我说了关于001的事,然后我们他和我说这些干嘛,他回复因为[2022-05-29]
放心啦,基金会其实是虚构的啦,别担心,就像那些鬼故事什么的,恐怖是恐怖,但是之后呢?现实中是没有的,就算有,又与我们何干?所以说,放心啦。 -
是的,你只需要更新CurrentControlSet键... ControlSet001和ControlSet002是CurrentControlSet交替备份,您不需要更新它们。 编辑:正如K注意到的, CurrentControlSet是ControlSet001或ControlSet002的交替符号链接。 另一个键保存为加载最后一次正确配置引导选项的备份。 编辑2: Microsoft知识库文章:什么是控制集? 什么是CurrentControlSet? Yes, you only need to u ...
-
Spring Batch - FlatFileItemReader \ 001分隔符问题(Spring Batch - FlatFileItemReader \001 delimiter issue)[2024-01-26]
我要回答我自己的问题。 实际问题是控制字符在linux中用作分隔符(^ A) 在Java中,当我使用string.split(“\ u0001”)时,它正在工作。 同样将它传递给Spring批处理flatfileitemreader作为分隔符,它就像一个魅力。 谢谢尚卡尔。 I am going to answer my own question. The actual issue was control character was used as delimiter in linux (^A) In Ja ... -
如何获得“irb(main):001:0>”提示符而不是“>>”(How do I get the “irb(main):001:0>” prompt instead of “>>”)[2022-08-08]
$ irb --help Usage: irb.rb [options] [programfile] [arguments] --prompt prompt-mode --prompt-mode prompt-mode Switch prompt mode. Pre-defined prompt modes are `default', `simple', `xmp' and `inf-ruby' $ irb --prompt inf-ruby i ... -
正如@mike sherrill'catcall'在评论中提到的那样,将2个数字乘以精度3将导致精度为6的数字。 您只需要另一个强制转换表达式,将结果恢复为3: (DT_NUMERIC,8,3)(DT_NUMERIC,8,3)(SUBSTRING(TotalDBRecords,44,8)) * .001 As mentioned by @mike sherrill 'catcall' in the comments, multiplying 2 numerics each with precision 3 ...
-
1是整数,001是字符串。 如果您尝试将3位数字系列显示为id或类似物并且正在递增,则需要将字符串“001”转换为整数,然后将其递增,然后将其转换回“0”填充字符串以供显示。 public string NextId(string currentId) { int i = 0; if (int.TryParse(currentId, out i)) { i++; return(i.ToString().PadLeft(3,'0')); } ...
-
整数不能在Python中具有前导零。 之前的前导零(Python 2)用于表示八进制数字。 由于许多人不知道并且为什么070 == 56而感到困惑,因此Python 3使得前导零非法。 您不应该将code转换为整数 - 仅存储数值变量中的实际数字(您打算进行计算)。 保持字符串: while True: code = input("Input a three digit code. Must be more than 001 and less than 100.") try: ...
-
strcat()需要一个以null结尾的字符串作为输入。 所以strcat(token和&current)将开始读取当前地址并继续运行直到找到null。 只是偶然,你当前在内存中的内容是“\ 001”,所以每次你执行strcat时它都会将所有内容复制到令牌中。 你应该做char current [] =“\ 0 \ 0”,然后用current [0] = chs [++ pos]赋值。 那样,current将始终具有null终止。 strcat() needs a null-terminated strin ...
-
嗯。 它的工作方式如下: “strcat删除了参数中的尾随空格(在单元格数组中除外),而cstrcat则保留了未触及的空格。” 来自http://www.gnu.org/software/octave/doc/interpreter/Concatenating-Strings.html 所以问题可能是:这种行为是否应该改变。 Hmm. It works how it is defined: "strcat removes trailing white space in the arguments (exce ...
-
该问题已通过使用org.apache.commons.lang3.StringEscapeUtils的escapeXml11(String input)方法处理该变量来解决: import static org.apache.commons.lang3.StringEscapeUtils.escapeXml11; ... public void initStringValue2() { stringValue = "EFGH" + '\u001c'; stringVa ...