初次涉及到大规模数据的查询问题。用比较简单的方法处理了一下。 问题描述:目前有一个40G的文件,这个文件的每一行的组成都是一样的, id 以及此id对应的数据内容。一共数据约1.3亿条。 要求,输入一个id,能够快速查找到此id所对应的内容。 简单的解决方法
初次涉及到大规模数据的查询问题。用比较简单的方法处理了一下。
问题描述:目前有一个40G的文件,这个文件的每一行的组成都是一样的, id 以及此id对应的数据内容。一共数据约1.3亿条。
要求,输入一个id,能够快速查找到此id所对应的内容。
简单的解决方法:先根据id,把数据分到1000个文件中去,即 id%1000 ,这种方法相对比较简单。
由于可能数据不是完全离散分布的,有的文件可能有80多M。所以当给定id时,就可以直接定位到它所在的文件。
使用php进行查找时,我们可以使用正则表达式。把文件读入到一个字符串中,然后使用正则表达式进行匹配即可。
正则为: "/".$id.".+\n/"

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.