简体   繁体   English

结果集到多哈希映射

[英]Result Set to Multi Hash Map

I have a situation here. 我这里有个情况。 I have a huge database with >10 columns and millions of rows. 我有一个大于10列和数百万行的庞大数据库。 I am using a matching algorithm which matches each input records with the values in database. 我正在使用一种匹配算法,该算法将每个输入记录与数据库中的值进行匹配。

The database operation is taking lot of time when there are millions of records to match. 当有数百万条记录要匹配时,数据库操作将花费大量时间。 I am thinking of using a multi-hash map or any resultset alternative so that i can save the whole table in memory and prevent hitting database again.... 我正在考虑使用多哈希映射或任何结果集替代方法,以便可以将整个表保存在内存中并防止再次命中数据库。

Can anybody tell me what should i do?? 谁能告诉我该怎么办?

I don't think this is the right way to go. 我认为这不是正确的方法。 You are trying to do the database's work manually in Java. 您正在尝试使用Java手动完成数据库的工作。 I'm not saying that you are not capable of doing this, but most databases have been developed for many years and are quite good in doing exactly the thing that you want. 我并不是说您没有能力做到这一点,但是大多数数据库已经开发了很多年,并且在完成您想要做的事情方面非常擅长。

However, databases need to be configured correctly for a given type of query to be executed fast. 但是,对于快速执行给定类型的查询,需要正确配置数据库。 So my suggestion is that you first check whether you can tweak the database configuration to improve the performance of the query. 因此,我的建议是您首先检查是否可以调整数据库配置以提高查询性能。 The most common thing is to add the right indexes to your table. 最常见的事情是向表中添加正确的索引。 Read How MySQL Uses Indexes or the corresponding part of the manual of your particular database for more information. 阅读MySQL如何使用索引或特定数据库手册的相应部分以获取更多信息。

The other thing is, if you have so much data storing everything in main memory is probably not faster and might even be infeasible. 另一件事是,如果您有太多的数据将所有内容存储在主存储器中,可能不会更快,甚至可能无法实现。 Not to say that you have to transfer the whole data first. 并不是说您必须先传输整个数据。

In any case, try to use a profiler to identify the bottleneck of the program first. 无论如何,请尝试首先使用探查器来确定程序的瓶颈。 Maybe the problem is not even on the database side. 也许问题甚至不在数据库方面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM