indexing

Is it better to create an index before filling a table with data, or after the data is in place?

馋奶兔 提交于 2019-12-17 21:57:18
问题 I have a table of about 100M rows that I am going to copy to alter, adding an index. I'm not so concerned with the time it takes to create the new table, but will the created index be more efficient if I alter the table before inserting any data or insert the data first and then add the index? 回答1: Creating index after data insert is more efficient way (it even often recomended to drop index before batch import and after import recreate it). Syntetic example (PostgreSQL 9.1, slow development

Clustered vs Non-Clustered

非 Y 不嫁゛ 提交于 2019-12-17 21:39:15
问题 My lower level knowledge of SQL (Server 2008) is limited, and is now being challanged by our DBAs. Let me explain (I have mentioned obvious statements in the hope that I am right, but if you see something wrong, please tell me) the scenario: We have a table which holds 'Court Orders' for people. When I created the table, (Name: CourtOrder), I created it like: CREATE TABLE dbo.CourtOrder ( CourtOrderID INT NOT NULL IDENTITY(1,1), (Primary Key) PersonId INT NOT NULL, + around 20 other fields of

What's the alternative to pandas chain indexing?

你说的曾经没有我的故事 提交于 2019-12-17 21:29:50
问题 I'm taking an online class to learn python and the instructor taught us that chain indexing was not a good idea. However, he failed to tell is the appropriate alternative to use. Suppose I have a Pandas data frame with rows indexed as ['1', '2', '3'] and columns with names ['a', 'b', 'c'] . What's the appropriate alternative to using the command df['1']['a'] to extract the value found in the first row and first column? 回答1: Use multi-axis indexing, e.g. df.loc['a', '1'] When you use df['1'][

MongoDB querying performance for over 5 million records

☆樱花仙子☆ 提交于 2019-12-17 21:24:56
问题 We've recently hit the >2 Million records for one of our main collections and now we started to suffer for major performance issues on that collection. They documents in the collection have about 8 fields which you can filter by using UI and the results are supposed to sorted by a timestamp field the record was processed. I've added several compound indexes with the filtered fields and the timetamp e.g: db.events.ensureIndex({somefield: 1, timestamp:-1}) I've also added couple of indexes for

Selecting multiple parts of a list

喜欢而已 提交于 2019-12-17 21:13:32
问题 I have a data frame with 100 entries, and I want to get a fields value for a subset of the entries. Specifically, I want every other 10 entries (i.e. indices 1-10,21-30,41-50,61-70,...) The only way I've been able to do this is via: c(data$field[1:10],data$field[21:30],...) But this seems like a horrible solution, especially if the size of the data frame changes. 回答1: You can do data$field[rep(c(TRUE, FALSE), each = 10)] where rep creates a vector of ten TRUE followed by ten FALSE and is

How To Create A 'Two-Sided' Unique Index On Two Fields?

一个人想着一个人 提交于 2019-12-17 21:05:26
问题 How can I efficiently create a unique index on two fields in a table like this: create table t (a integer, b integer); where any unique combination of two different numbers cannot appear more than once on the same row in the table. In order words if a row exists such that a=1 and b=2, another row cannot exist where a=2 and b=1 or a=1 and b=2. In other words two numbers cannot appear together more than once in any order. I have no idea what such a constraint is called, hence the 'two-sided

“Specified key was too long; max key length is 1000 bytes”

十年热恋 提交于 2019-12-17 20:35:16
问题 I can't create index on varchar(500) . MySQL: Specified key was too long; max key length is 1000 bytes 回答1: latin1 = 1 byte = 1 character uft8 = 3 byte = 1 character gbk = 2 byte = 1 character 来源: https://stackoverflow.com/questions/1037598/specified-key-was-too-long-max-key-length-is-1000-bytes

Pattern matching on jsonb key/value

ぐ巨炮叔叔 提交于 2019-12-17 20:27:30
问题 I am using PostgreSQL 9.4. My table has a jsonb column: CREATE TABLE "PreStage".transaction ( transaction_id serial NOT NULL, transaction jsonb CONSTRAINT pk_transaction PRIMARY KEY (transaction_id) ); CREATE INDEX idxgin ON "PreStage".transaction USING gin (transaction); I store transactions in terms of key / value in the JSONB column. One of the requirements is to search customer name from the key value, hence I am running a query like: SELECT transaction as data FROM "PreStage".transaction

Using indexes in json array in PostgreSQL

寵の児 提交于 2019-12-17 20:25:14
问题 Referring to the original stackoverflow question, I am trying to apply gin indexes to keys in objects of an array in Postgres 9.4 but I'm not getting the results as stated in the first answer. Can you please rectify the error? The steps I followed have been written below. Part 1: Creating table and indexes CREATE TABLE tracks (id serial, artists jsonb); CREATE INDEX tracks_artists_gin_idx ON tracks USING gin (artists); INSERT INTO tracks (id, artists) VALUES (1, '[{"name": "blink-182"}]');

MySQL Auto Increment Custom Values

穿精又带淫゛_ 提交于 2019-12-17 19:59:49
问题 I am trying to make a column in a mysql database that auto increments by one but goes from 0-Z and then rolls. For example 000, 001, 002, ..., 009, 00A, 00B, ..., 00Z, 010, ..., 0ZZ, ..., 100. I would like to have the database create the column through an auto incrementing field. The ideas I have are: Create a column for each character that goes from 0-36, then auto increment row N (where N is the least significant digit) by 1. Then add a trigger on each column to add 1 to column N-1 when