database-indexes

Oracle - Create an index only if not exists

半城伤御伤魂 提交于 2021-02-08 14:38:28
问题 Is there any way to create indexes in oracle only if they don't exists ? Something like CREATE INDEX IF NOT EXISTS ord_customer_ix ON orders (customer_id); 回答1: Add an index only if not exists: declare already_exists exception; columns_indexed exception; pragma exception_init( already_exists, -955 ); pragma exception_init(columns_indexed, -1408); begin execute immediate 'create index ord_customer_ix on orders (customer_id)'; dbms_output.put_line( 'created' ); exception when already_exists or

Oracle - Create an index only if not exists

让人想犯罪 __ 提交于 2021-02-08 14:38:06
问题 Is there any way to create indexes in oracle only if they don't exists ? Something like CREATE INDEX IF NOT EXISTS ord_customer_ix ON orders (customer_id); 回答1: Add an index only if not exists: declare already_exists exception; columns_indexed exception; pragma exception_init( already_exists, -955 ); pragma exception_init(columns_indexed, -1408); begin execute immediate 'create index ord_customer_ix on orders (customer_id)'; dbms_output.put_line( 'created' ); exception when already_exists or

Oracle - Index use with optional parameters

情到浓时终转凉″ 提交于 2021-02-08 04:03:43
问题 I use the following trick to be able to index a column that has some nulls: create index xx_people_idx1 on xx_people(id_number, -1); This works great. Sadly this does not help for when you use optional parameters though: select * from xx_people where id_number = nvl(:p_id_number, id_number); This results in a full table scan, even when you provide a value for p_id_number . Is there a trick to use the index in this situation? Since searching by id number and name are my only 2 searches this is

SQL Server Web vs Standard edition

谁说胖子不能爱 提交于 2020-12-29 09:06:34
问题 I have found out that there's two versions of SQL Server types that are very different in terms of pricing... The Web version from my host provider costs about 13$ per 2 core packs, whereas the Standard edition is right around 200$. From my standpoint, we expect our database to be around 150-200GB in size, only few tables would take up most of that space. So my only concern is would the web version of SQL Server support this large database and not cause any performance issues to the end users

Indexing for BINARY LIKE operations in MySQL

别来无恙 提交于 2020-01-30 06:26:46
问题 I know that varchar_pattern_ops exists in Postgresql for fast, index-based searches in a LIKE query, but is there any similar functionality for MySQL? I currently have a Django-MySQL setup where I have this query which runs on a non-indexed field and with a BINARY LIKE operation, and it takes over a minute to complete. My query is a partial search from the beginning of the text - text% . This is the table structure. The table actually contains over 20 fields, but I've included just the

MySQL index for normal column and full text column

时光总嘲笑我的痴心妄想 提交于 2020-01-15 09:48:09
问题 I'm trying to speed up a query for the below: My table has around 4 million records. EXPLAIN SELECT * FROM chrecords WHERE company_number = 'test' OR MATCH (company_name,registered_office_address_address_line_1,registered_office_address_address_line_2) AGAINST('test') LIMIT 0, 10; +------+-------------+-----------+------+------------------+------+---------+------+---------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+---------

PostgreSQL: Create index on length of all table fields

情到浓时终转凉″ 提交于 2020-01-15 03:31:04
问题 I have a table called profile , and I want to order them by which ones are the most filled out. Each of the columns is either a JSONB column or a TEXT column. I don't need this to a great degree of certainty, so typically I've ordered as follow: SELECT * FROM profile ORDER BY LENGTH(CONCAT(profile.*)) DESC; However, this is slow, and so I want to create an index. However, this does not work: CREATE INDEX index_name ON profile (LENGTH(CONCAT(*)) Nor does CREATE INDEX index_name ON profile

Does SQL Server support hash indexes?

亡梦爱人 提交于 2020-01-14 02:49:11
问题 Are all the indexes in SQL Server B Tree? Surely primary keys and foreign should be hash based indexes? 回答1: Not all indexes in SQL Server are B-tree indexes (SQL Server 2012 added columnstore indexes which are a bit different), but there is no such thing as a hash-based index there (yet). 回答2: Here's a pretty straight forward article explaining that all indices are b tree indices in SQL Server: http://msdn.microsoft.com/en-us/library/ms177443(v=sql.105).aspx I think if you want to get more

Creating Indexes on DB with Hibernate @Index Annotation

陌路散爱 提交于 2020-01-10 12:04:13
问题 I have annotation-driven hibernate capabilies on my project. Now I want to create an index over a column. My current column definition is @NotNull @Column(name = "hash") private String hash; and I add @Index annotation here. @NotNull @Column(name = "hash") @Index(name="hashIndex") private String hash; and then DROP TABLE and restart Tomcat server. After the server is instantiated, the table is created but I can't see new index on following query. SHOW INDEX FROM tableName It is expected to

PostgreSQL citext index vs lower expression index performance

*爱你&永不变心* 提交于 2020-01-04 05:19:07
问题 I want to decide between using a citext column with an index or using a text column with an index on lower() . I performed some benchmarks. To my surprise the search with the index on lower() causes an index scan, but in the citext case I get an index only scan. I was expecting the index on lower() to cause an index only scan too. Also, the total cost with the citext index is 4.44, but with the index on lower() , the total cost is 8.44. So the first thing coming to my mind is that the citext