Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hUEac-0001ad-L2 for pgsql-performance@arkaria.postgresql.org; Fri, 24 May 2019 18:06:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hUEab-0003G6-70 for pgsql-performance@arkaria.postgresql.org; Fri, 24 May 2019 18:06:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hUEaa-00031U-K2 for pgsql-performance@lists.postgresql.org; Fri, 24 May 2019 18:06:44 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hUEaX-0005Pu-5c for pgsql-performance@postgresql.org; Fri, 24 May 2019 18:06:43 +0000 Received: by mail-wm1-x343.google.com with SMTP id v19so1748162wmh.0 for ; Fri, 24 May 2019 11:06:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=yKHY8nyzrDhecPN7frkh4uxC16hf9N4S3qSEKSCbdkQ=; b=zAwGZJ23yoHUzh3q2OeWZSXWL9aYQC+nZs23rM7yQpbsFteTagQtA8Tuz7yZNLYRod BqfPuQEpOv84SGP/XfFyFLCgdjTRMe2a8pplsWDAs98pPcjQUycIlYPQEEKaWa7OHe15 Ce4VxIDTuhNmu9A4vq29kG9GpZBbXtGRciEAaUzFL6ucIcAT1JQuXCS5E/3MxWywjeSL wZJLqYOCSyVwXTPwFWRji67XG79ItqDWyEMmunrlBoIOeO5+iBwl6wbxbC1fwVbkOtCr bDauxUYBE5W17PJDPVTGz/dbVUWOM//TG3QjWHfMaRTAoyIPTvTEYwiMA3uWqfQcFSQP XqKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=yKHY8nyzrDhecPN7frkh4uxC16hf9N4S3qSEKSCbdkQ=; b=gtkcDNJfvYh4E86YolfoZUib5ORtjCugIgVrJAwIyDYfhDC3GRGsTI6tFy1oaWzHAd +8k54yeCwBpJlE3dSwaoNTjxRynYvHA610JkJaLoSfYY6L8inMi31JLgd/CyRSzEw/kg koKWWyHIiZj7qbqsRfJkfqmG6XwDv20P+F9zBrJFg35eFMR/867MWOtpYwpbYur46BVb cL/kead9L5xRXjBSAIig+Y+Lb1yzxeSVDfjAmL0mMMf+u/TX4GE79m4h/h1qYlmy4fSU CEg0z/V/PpFHZfz1dHTsvXrBEnB0bAkbKLO3r8lxl+Zlt8dDsI4+iOEABsdCeSnwBvj/ KthA== X-Gm-Message-State: APjAAAWZUfJztM5j24jjQhOfitb7wP4Ved+0qmnsUSaPzxRAQ2uDmB6x EbduE0n29+rwSQCId1vRTxv71fcCpkA= X-Google-Smtp-Source: APXvYqw/7Eyubx+9zk/9AXKHSYnZbYT15z8rI0hyNHLgOx64PEPzE0IoKnBcfnJnMPvu+xKPll/6vw== X-Received: by 2002:a7b:cb01:: with SMTP id u1mr16600680wmj.153.1558721199308; Fri, 24 May 2019 11:06:39 -0700 (PDT) Received: from localhost (ip-86-49-243-43.net.upcbroadband.cz. [86.49.243.43]) by smtp.gmail.com with ESMTPSA id x6sm4512469wru.36.2019.05.24.11.06.30 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 24 May 2019 11:06:31 -0700 (PDT) Date: Fri, 24 May 2019 20:06:29 +0200 From: Tomas Vondra To: George Neuner Cc: pgsql-performance@postgresql.org Subject: Re: Use Postgres as a column store by creating one table per column Message-ID: <20190524180629.42d3u4m7a3jgh5hq@development> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, May 23, 2019 at 01:08:42AM -0400, George Neuner wrote: >On Tue, 21 May 2019 21:28:07 -0700, Lev Kokotov > wrote: > >>Is it efficient to use Postgres as a column store by creating one >table per >>column? >> >>I would query it with something like `[...] UNION SELECT value AS >>FROM
WHERE value = UNION [...]` to build a row. > >I think you mean JOIN. > >You'd need more than that: Postgresql uses MVCC for concurrency, so >whenever you update any row in a table, the ordering of the rows >within the table changes.  And the JOIN operation inherently is >unordered - you need to sort the result deliberately to control >ordering. > >To emulate a column-store, at the very least you need a way to >associate values from different "columns" that belong to the same >"row" of the virtual table.  IOW, every value in every "column" needs >an explicit "row" identifier.  E.g., > >   col1 = { rowid, value1 }, col2 = { rowid, value2 }, ... > >For performance you would need to have indexes on at least the rowid >in each of the "column" tables. > >This is a bare minimum and can only work if the columns of your >virtual table and the queries against it are application controlled or >statically known.  If you want to do something more flexible that will >support ad hoc table modifications, elastically sized values (strings, >bytes, arrays, JSON, XML), etc. this example is not suffice and the >implementation can get very complicated very quickly > > >Justin Pryzby was not joking when he said the performance could be >awful ... at least as compared to a more normal row-oriented >structure.  Performance of a query that involves more than a handful >of "columns", in general, will be horrible.  It is up to you to decide >whether some (maybe little) increase in performance in processing >*single* columns will offset likely MASSIVE loss of performance in >processing multiple columns. > Maybe take a look at this paper: http://db.csail.mit.edu/projects/cstore/abadi-sigmod08.pdf which essentially compares this approach to a "real" column store. It certainly won't give you performance comparable to column store, it adds quite a bit of overhead (disk space because of row headers, CPU because of extra joins, etc.). And it can't give you the column-store benefits - compression and/or more efficient execution. > >>I'm thinking since Postgres stores tables in continuous blocks of >16MB each >>(I think that's the default page size?) > >Default page size is 8 KB.  You'd have to recompile to change that, >and it might break something - a whole lot of code depends on the >knowing the size of storage pages. > > Right. And the largest page size is 64kB. But 8kB is a pretty good trade-off, in most cases. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services