PHP Classes

File: SQL File

Recommend this page to a friend!
  Packages of Matthew Asham   Binkterm PHP   database/migrations/v1.11.0.15_users_lower_username_index.sql   Download  
File: database/migrations/v1.11.0.15_users_lower_username_index.sql
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Binkterm PHP
Bulletin board system based on the Web
Author: By
Last change:
Date: 5 days ago
Size: 987 bytes
 

Contents

Class file image Download
-- Migration: v1.11.0.15 - Add case-insensitive functional index on users.username -- -- Several hot-path queries use LOWER(username) comparisons but no functional -- index existed, forcing PostgreSQL to seq scan the users table: -- -- 1. Auth::login() WHERE LOWER(username) = LOWER(?) AND is_active = TRUE -- 2. BinkdProcessor WHERE LOWER(real_name) = LOWER(?) OR LOWER(username) = LOWER(?) -- 3. MessageHandler WHERE LOWER(real_name) = LOWER(?) OR LOWER(username) = LOWER(?) -- 4. Collision trigger WHERE LOWER(username) = LOWER(NEW.real_name) OR ... -- -- A UNIQUE index on LOWER(username) covers all of the above: plain lookups use -- it directly, and OR conditions with the existing users_real_name_lower_idx -- allow PostgreSQL to use a bitmap OR index scan instead of a seq scan. -- UNIQUE also enforces case-insensitive username uniqueness at the DB level. CREATE UNIQUE INDEX IF NOT EXISTS idx_users_lower_username ON users (LOWER(username));