首页 \ 问答 \ 如何有效地获取日期范围内的分页查询结果(How to efficiently get paged query results for a date range)

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

相关问答

更多

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)