走过路过不要错过!望有经验兄台分享一下。
一个关于用户注册和查询的问题。如果说我这个系统有一千万个用户我不用一个表存这么多用户。
多建一些用户表每一个用户表存一万个用户这样就需要一千个表。
当用户登录时从一万个数据里面查找和从一千万个数据里面查找速度必然不同。
但是我怎么能够知道这个用户在一千个用户表当中哪一个表里面呢?
如果可以快速的知道在哪个表里面一条查询语句就可以判断密码是否正确登录成功与否了!
用户注册时只要满足6-18位字母数字下划线组合而且数据库里面没有就可以注册成功。
但是从一千个用户表里面用ajax验证用户是否存在也是一个考验!这里我应该怎么设计呢?
这个和申请qq号还不一样qq号是腾讯给的所以完全可以知道这个号段在哪个表里面。
望各位兄台有经验的分享一下。万分感谢!蓝色字迹两个问题希望大家帮忙出出主意。
回复讨论(解决方案)
字母数字加下划线共有 37 种首字符,如果区分大小写则有 63 种(不过数据库字符串比较是不区分大小写的,需指定为二进制方式才会区分)
取前两位做键,则 37 * 37 = 1369,已经能满足你 一千个表 表的设想了
//设用户名为$username = 'abcd';//构造表名$tbl_name = 'U' . substr($username, 0, 2);//则查询串为$srl = "select * from $tbl_name where username='$username'";
你需要再单独建一个索引表,表里面记录各个表中用户的排序情况。检索的时候只要先检索这个表,定位用户所在的范围,然后再检索那个表就可以了。
你需要再单独建一个索引表,表里面记录各个表中用户的排序情况。检索的时候只要先检索这个表,定位用户所在的范围,然后再检索那个表就可以了。
这位兄台的思路也是我最先想到的但是我感觉这样还要查询两次数据库可不可以查询一次数据库呢?
字母数字加下划线共有 37 种首字符,如果区分大小写则有 63 种(不过数据库字符串比较是不区分大小写的,需指定为二进制方式才会区分)
取前两位做键,则 37 * 37 = 1369,已经能满足你 一千个表 表的设想了
//设用户名为$username = 'abcd';//构造表名$tbl_name = 'U' . substr($username, 0, 2);//则查询串为$srl = "select * from $tbl_name where username='$username'";
恩,兄台的这个思路确实给了我指引而且是一个很好而高效的方案。
那如果说我的表名是从user1一直到user1000命名的。那我应该怎么定位用户在哪个表里呢?
那就是自找麻烦了。
你需要另建一张表,用于存储分表信息。查询时先查这张表,取得真实存放的表名
而这张表依然是存放着以什么字符串开头的在什么表中
那就是自找麻烦了。
你需要另建一张表,用于存储分表信息。查询时先查这张表,取得真实存放的表名
而这张表依然是存放着以什么字符串开头的在什么表中
我也感觉表名如果用user1到user1000来命名确实很难操作。
2楼兄台思路可行不过要查询两次。
还有没有其他有经验的兄台进来分享一下

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Alipay PHP...

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
