CREATE INDEX customers_user_name_idx ON customers (user_name);
CREATE INDEX customers_last_name_first_name_idx ON customers (last_name, first_name);
DROP INDEX IF EXISTS customers_city_idx;Una pedazo de búsqueda que no sé a qué viene:
SELECT
c.first_name,
c.last_name,
COUNT(o.order_id) AS NumOforders
FROM customers AS c
INNER JOIN orders AS o
ON o.customer_id = c.customer_id
WHERE c.last_name IN ('Smith', 'Jones')
GROUP BY c.first_name, c.last_name;Índices parciales para una porción de la tabla:
CREATE INDEX users_user_name_internal_idx ON users (user_name)
WHERE email_address LIKE '%@wellsfargo.com';Los índices pueden estar ordenados:
CREATE INDEX logins_date_time_idx ON logins (date_time DESC, user_name);_pkey y _idx son sufijos estándar.
La movida de los cluster index y cómo recluster un index:
To cluster your database table using an existing index (say products_product_name_idx) on the products table you would use:
CLUSTER products USING products_product_name_idx;
If you have already established what index should be clustered on you can simply tell the system which table to apply the cluster on.
CLUSTER products;
And if you want to cluster every table in your database that has an identified index to use you can simply call
CLUSTER;La parte de los no-cluster index me la fumo.
Los índices pueden ser expresiones:
CREATE UNIQUE INDEX unique_manufacture_company_name_idx ON manufacture(LOWER(company_name));