如何有效地获取日期范围内的分页查询结果(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
2021-09-18 12:09

满意答案

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, &current) 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的事,然后我们他和我说这些干嘛,他回复因为

放心啦,基金会其实是虚构的啦,别担心,就像那些鬼故事什么的,恐怖是恐怖,但是之后呢?现实中是没有的,就算有,又与我们何干?所以说,放心啦。

CurrentControlSet与ControlSet001和ControlSet002有什么不同?(How does CurrentControlSet differ from ControlSet001 and ControlSet002?)

是的,你只需要更新CurrentControlSet键... ControlSet001和ControlSet002是CurrentControlSet交替备份,您不需要更新它们。 编辑:正如K注意到的, CurrentControlSet是ControlSet001或ControlSet002的交替符号链接。 另一个键保存为加载最后一次正确配置引导选项的备份。 编辑2: Microsoft知识库文章:什么是控制集? 什么是CurrentControlSet? Yes, you only need...

Spring Batch - FlatFileItemReader \ 001分隔符问题(Spring Batch - FlatFileItemReader \001 delimiter issue)

我要回答我自己的问题。 实际问题是控制字符在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) ...

如何获得“irb(main):001:0>”提示符而不是“>>”(How do I get the “irb(main):001:0>” prompt instead of “>>”)

$ 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-r...

试图通过乘以.001来移动小数。(Trying to move the decimal by multiplying by .001. Why is it changing the scale & precision?)

正如@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 precisi...

如何将字符串“001”转换为int 001(How to convert a string “001” to int 001)

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 3.4.3中使用001时,令牌无效(Invalid token when using 001 in Python 3.4.3)

整数不能在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时添加\ 001(Why \001 is added when strcat is invoked)

strcat()需要一个以null结尾的字符串作为输入。 所以strcat(token和&current)将开始读取当前地址并继续运行直到找到null。 只是偶然,你当前在内存中的内容是“\ 001”,所以每次你执行strcat时它都会将所有内容复制到令牌中。 你应该做char current [] =“\ 0 \ 0”,然后用current [0] = chs [++ pos]赋值。 那样,current将始终具有null终止。 strcat() needs a null-terminated ...

Octave strcat忽略添加的空格(Octave strcat ignores added spaces)

嗯。 它的工作方式如下: “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 ...

使用escape =“false”和值更新h:outputText,其中包含'\ u001c'(Update h:outputText with escape=“false” and value, that contains '\u001c')

该问题已通过使用org.apache.commons.lang3.StringEscapeUtils的escapeXml11(String input)方法处理该变量来解决: import static org.apache.commons.lang3.StringEscapeUtils.escapeXml11; ... public void initStringValue2() { stringValue = "EFGH" + '\u001c'; str...

相关文章

更多

Guava Range类-范围处理

C upperEndpoint()返回此范围的上限端点

Guava学习笔记:Range

  在Guava中新增了一个新的类型Range,从名字就可以了解到,这个是和区间有关的数据结构。从Go ...

MongoDB学习 (五):查询操作符(Query Operators).1st

查询操作符(Query Operators)可以让我们写出复杂查询条件,让我们使用的过程更加灵活。官方 ...

[转]So You Want To Be A Producer

pro-du-cer n. 1. Someone from a game publisher who ...

常用HQL(Hibernate Query Language)查询

查询一个对象(实体类必须有一个不带参数的构造方法),使用select查询,基于投影的查询,通过在列表中 ...

Solr 使用自定义 Query Parser

原文出处:http://blog.chenlb.com/2010/08/solr-use-custom ...

Solr 使用自定义 Query Parser

原文出处:http://blog.chenlb.com/2010/08/solr-use-custom ...

Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing

http://spark-project.org/ 项目首页 http://shark.cs.berk ...

Spring Data: a new perspective of data operations

Spring Data: a new perspective of data operations ...

Solr: a custom Search RequestHandler

As you know, I've been playing with Solr lately, tr ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本