database-partitioning

SELECT TOP record for each year

社会主义新天地 提交于 2019-12-01 09:13:50
问题 I am trying to recap on my sql skill, now I am trying to run a simple query on northwinddb to show me the top customer for each year, but as soon as I use the TOP function only 1 record gets display no matter on what I partition by, This is my T-SQL code SELECT DISTINCT TOP 1 C.CompanyName , YEAR(O.OrderDate) AS Year , SUM(Quantity) OVER(PARTITION BY C.CompanyName, YEAR(O.OrderDate)) AS Total FROM Customers C JOIN Orders O ON C.CustomerID = O.CustomerID JOIN [Order Details] OD ON O.OrderID =

How do you set Incemental to true for multiple tables with the same owner using DBMS_STATS.set_table_prefs?

情到浓时终转凉″ 提交于 2019-12-01 08:40:54
问题 I have around 40-50 tables in my oracle database that are partitioned. Using DBMS_STATS.set_table_prefs, I want to set "Incremental" to true for all of my partitioned tables. Can anyone help me with this? Below is the query: SELECT DISTINCT (table_name), partitioning_type, subpartitioning_type, OWNER FROM all_part_tables WHERE OWNER = 'user' ORDER BY table_name ASC ; 回答1: This PL/SQL block (which is based on your comment in another question) loops through partitioned tables for a user and

Select from several partitions at once

夙愿已清 提交于 2019-12-01 00:28:48
Excuse me for my english. I have 2 tables, both partitioned by date interval, but on different fields. There is a big amount of records in both tables(~100kk in each partition). First table keep it's 3 last(by date) partitions in fast discks tablespace, others partitions is in slow discks tablespace. Also I have some system, which processing data. It execute processes in parallel, each one get data from first table by select statement and put processed data into second table. So I need select data from first table only from "fast"(!) partitions to put it in second table. But second table

How to partition an oracle table by a date column?

情到浓时终转凉″ 提交于 2019-11-30 17:29:59
问题 I have a table in oracle: CREATE TABLE transaction ( id INT NOT NULL, accountnumber VARCHAR NOT NULL, stmtvaluedate DATE NOT NULL, ... ) And I want to partition this table by the stmtvaluedate column. My goal is to create a new partition after a month have passed. Is there any good script, for it? Or I have to create static numbers of partitions? The best would be: if a month have passed, a new partition will be created automatically. Can anyone give me an example about how to partition a

Self-managing PostgreSQL partition tables

强颜欢笑 提交于 2019-11-30 16:06:29
问题 I am trying to make a self-managing partition table setup with Postgres. It all revolves around this function but I can't seem to get Postgres to accept my table names. Any ideas or examples of self-managing partition table trigger functions? My current function: DECLARE day integer; year integer; tablename text; startdate text; enddate text; BEGIN day:=date_part('doy',to_timestamp(NEW.date)); year:=date_part('year',to_timestamp(NEW.date)); tablename:='pings_'||year||'_'||day||'_'||NEW.id; --

Self-managing PostgreSQL partition tables

跟風遠走 提交于 2019-11-30 16:00:15
I am trying to make a self-managing partition table setup with Postgres. It all revolves around this function but I can't seem to get Postgres to accept my table names. Any ideas or examples of self-managing partition table trigger functions? My current function: DECLARE day integer; year integer; tablename text; startdate text; enddate text; BEGIN day:=date_part('doy',to_timestamp(NEW.date)); year:=date_part('year',to_timestamp(NEW.date)); tablename:='pings_'||year||'_'||day||'_'||NEW.id; -- RAISE EXCEPTION 'tablename=%',tablename; PERFORM 'tablename' FROM pg_tables WHERE 'schemaname'

MySQL 5.5 partition table by A-Z

风流意气都作罢 提交于 2019-11-30 14:51:21
I understand that as of MySQL 5.5, you can now partition a table by non-integer values like a varchar. I have a table where I perform a lot of lookups on a single varchar column, hence I would like to partition on that for performance reasons. In all instances, the value of the column is a single alphabetical word (strictly lower case a-z, enforced by validation). What I would like to do is partition this table by the first letter in each word stored, so all words beginning with 'a' go in the first partition, 'b' in the second etc. My gut feeling is that I could probably construct the create

How do I execute raw SQL in a django migration

半城伤御伤魂 提交于 2019-11-30 13:42:59
问题 I am aware of the cursor object in Django. Is there any other preferred way to execute raw SQL in migrations? I want to introduce postgresql partitioning for one of my models tables. The partition logic is a bunch of functions and triggers that have to be added to the database on setup which I'd like to automate. 回答1: One way: The best way I found to do this is using RunSQL: Migrations contains the RunSQL class. To do this: ./manage.py makemigrations --empty myApp edit the created migrations

Mysql improve SELECT speed

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 12:42:24
I'm currently trying to improve the speed of SELECTS for a MySQL table and would appreciate any suggestions on ways to improve it. We have over 300 million records in the table and the table has the structure tag, date, value. The primary key is a combined key of tag and date. The table contains information for about 600 unique tags most containing an average of about 400,000 rows but can range from 2000 to over 11 million rows. The queries run against the table are: SELECT date, value FROM table WHERE tag = "a" AND date BETWEEN 'x' and 'y' ORDER BY date ....and there are very few if any

How do I execute raw SQL in a django migration

不羁岁月 提交于 2019-11-30 08:19:31
I am aware of the cursor object in Django. Is there any other preferred way to execute raw SQL in migrations? I want to introduce postgresql partitioning for one of my models tables. The partition logic is a bunch of functions and triggers that have to be added to the database on setup which I'd like to automate. One way: The best way I found to do this is using RunSQL: Migrations contains the RunSQL class. To do this: ./manage.py makemigrations --empty myApp edit the created migrations file to include: operations = [ migrations.RunSQL('RAW SQL CODE') ] As Nathaniel Knight mentioned, RunSQL