Thread: Add table access method as an option to pgbench
Hi Hackers, I noticed that there is a table access method API added starting from PG12. In other words, Postgresql open the door for developers to add their own access methods, for example, zheap, zedstore etc. However, the current pgbench doesn't have an option to allow user to specify which table access method to use during the initialization phase. If we can have an option to help user address this issue, it would be great. For example, if user want to do a performance benchmark to compare "zheap" with "heap", then the commands can be something like below: pgbench -d -i postgres --table-am=heap pgbench -d -i postgres --table-am=zheap I know there is a parameter like below available in postgresql.conf: #default_table_access_method = 'heap' But, providing another option for the end user may not be a bad idea, and it might make the tests easier at some points. The attached file is quick patch for this. Thoughts? Thank you, -- David Software Engineer Highgo Software Inc. (Canada) www.highgo.ca
Attachment
On Tue, Nov 24, 2020 at 03:32:38PM -0800, David Zhang wrote: > But, providing another option for the end user may not be a bad idea, and it > might make the tests easier at some points. My first thought is that we have no need to complicate pgbench with this option because there is a GUC able to do that, but we do that for tablespaces, so... No objections from here. > The attached file is quick patch for this. > > Thoughts? This patch does not apply on HEAD, where you can just use appendPQExpBuffer() to append the new clause to the CREATE TABLE query. This needs proper documentation. -- Michael
Attachment
Thank a lot for your comments, Michael. On 2020-11-24 7:41 p.m., Michael Paquier wrote: > On Tue, Nov 24, 2020 at 03:32:38PM -0800, David Zhang wrote: >> But, providing another option for the end user may not be a bad idea, and it >> might make the tests easier at some points. > My first thought is that we have no need to complicate pgbench with > this option because there is a GUC able to do that, but we do that for > tablespaces, so... No objections from here. > >> The attached file is quick patch for this. >> >> Thoughts? > This patch does not apply on HEAD, where you can just use > appendPQExpBuffer() to append the new clause to the CREATE TABLE > query. This needs proper documentation. The previous patch was based on branch "REL_13_STABLE". Now, the attached new patch v2 is based on master branch. I followed the new code structure using appendPQExpBuffer to append the new clause "using TABLEAM" in a proper position and tested. In the meantime, I also updated the pgbench.sqml file to reflect the changes. > -- > Michael -- David Software Engineer Highgo Software Inc. (Canada) www.highgo.ca
Attachment
On Wed, Nov 25, 2020 at 12:13:55PM -0800, David Zhang wrote: > The previous patch was based on branch "REL_13_STABLE". Now, the attached > new patch v2 is based on master branch. I followed the new code structure > using appendPQExpBuffer to append the new clause "using TABLEAM" in a proper > position and tested. In the meantime, I also updated the pgbench.sqml file > to reflect the changes. + <varlistentry> + <term><option>--table-am=<replaceable>TABLEAM</replaceable></option></term> + <listitem> + <para> + Create all tables with specified table access method + <replaceable>TABLEAM</replaceable>. + If unspecified, default is <literal>heap</literal>. + </para> + </listitem> + </varlistentry> This needs to be in alphabetical order. And what you say here is wrong. The default would not be heap if default_table_access_method is set to something else. I would suggest to use table_access_method instead of TABLEAM, and keep the paragraph minimal, say: "Create tables using the specified table access method, rather than the default." --table-am is really the best option name? --table-access-method sounds a bit more consistent to me. + if (tableam != NULL) + { + char *escape_tableam; + + escape_tableam = PQescapeIdentifier(con, tableam, strlen(tableam)); + appendPQExpBuffer(&query, " using %s", escape_tableam); + PQfreemem(escape_tableam); + } The order is wrong here, generating an unsupported grammar, see by yourself with this command: pgbench --partition-method=hash --table-am=heap -i --partitions 2 This makes the patch trickier than it looks as the USING clause is located between PARTITION BY and WITH. Also, partitioned tables cannot use the USING clause so you need to be careful that createPartitions() also uses the correct table AM. This stuff needs tests. -- Michael
Attachment
Hello David, > The previous patch was based on branch "REL_13_STABLE". Now, the attached new > patch v2 is based on master branch. I followed the new code structure using > appendPQExpBuffer to append the new clause "using TABLEAM" in a proper > position and tested. In the meantime, I also updated the pgbench.sqml file to > reflect the changes. My 0.02€: I'm fine with the added feature. The patch lacks minimal coverage test. Consider adding something to pgbench tap tests, including failures (ie non existing method). The option in the help string is not at the right ab place. I would merge the tableam declaration to the previous one with a extended comments, eg "tablespace and access method selection". escape_tableam -> escaped_tableam ? -- Fabien.
Thanks a lot again for the review and comments. On 2020-11-25 9:36 p.m., Michael Paquier wrote: > On Wed, Nov 25, 2020 at 12:13:55PM -0800, David Zhang wrote: >> The previous patch was based on branch "REL_13_STABLE". Now, the attached >> new patch v2 is based on master branch. I followed the new code structure >> using appendPQExpBuffer to append the new clause "using TABLEAM" in a proper >> position and tested. In the meantime, I also updated the pgbench.sqml file >> to reflect the changes. > + <varlistentry> > + <term><option>--table-am=<replaceable>TABLEAM</replaceable></option></term> > + <listitem> > + <para> > + Create all tables with specified table access method > + <replaceable>TABLEAM</replaceable>. > + If unspecified, default is <literal>heap</literal>. > + </para> > + </listitem> > + </varlistentry> > This needs to be in alphabetical order. The order issue is fixed in v3 patch. > And what you say here is > wrong. The default would not be heap if default_table_access_method > is set to something else. Right, if user change the default settings in GUC, then the default is not `heap` any more. > I would suggest to use table_access_method > instead of TABLEAM, All other options if values are required, the words are all capitalized, such as TABLESPACE. Therefore, I used TABLEACCESSMETHOD in stead of table_access_method in v3 patch. > and keep the paragraph minimal, say: > "Create tables using the specified table access method, rather than > the default." Updated in v3 patch. > > --table-am is really the best option name? --table-access-method > sounds a bit more consistent to me. Updated in v3 patch. > > + if (tableam != NULL) > + { > + char *escape_tableam; > + > + escape_tableam = PQescapeIdentifier(con, tableam, strlen(tableam)); > + appendPQExpBuffer(&query, " using %s", escape_tableam); > + PQfreemem(escape_tableam); > + } Thanks for pointing this out. The order I believe is fixed in v3 patch. > The order is wrong here, generating an unsupported grammar, see by > yourself with this command: > pgbench --partition-method=hash --table-am=heap -i --partitions 2 Tested in v3 patch, with a command like, pgbench --partition-method=hash --table-access-method=heap -i --partitions 2 > > This makes the patch trickier than it looks as the USING clause is > located between PARTITION BY and WITH. Also, partitioned tables > cannot use the USING clause so you need to be careful that > createPartitions() also uses the correct table AM. > > This stuff needs tests. 3 test cases has been added the tap test, but honestly I am not sure if I am following the rules. Any comments will be great. > -- > Michael -- David Software Engineer Highgo Software Inc. (Canada) www.highgo.ca
Attachment
Thanks Fabien for the comments. On 2020-11-25 11:29 p.m., Fabien COELHO wrote: > > Hello David, > >> The previous patch was based on branch "REL_13_STABLE". Now, the >> attached new patch v2 is based on master branch. I followed the new >> code structure using appendPQExpBuffer to append the new clause >> "using TABLEAM" in a proper position and tested. In the meantime, I >> also updated the pgbench.sqml file to reflect the changes. > > My 0.02€: I'm fine with the added feature. > > The patch lacks minimal coverage test. Consider adding something to > pgbench tap tests, including failures (ie non existing method). I added 3 test cases to the tap tests, but not sure if they are following the rules. One question about the failures test, my thoughts is that it should be in the no_server test cases, but it is hard to verify the input as the table access method can be any name, such as zheap, zedstore or zheap2 etc. Any suggestion will be great. > > The option in the help string is not at the right ab place. Fixed in v3 patch. > > I would merge the tableam declaration to the previous one with a > extended comments, eg "tablespace and access method selection". Updated in v3 patch. > > escape_tableam -> escaped_tableam ? Updated in v3 patch. By the way, I saw the same style for other variables, such as escape_tablespace, should this be fixed as well? -- David Software Engineer Highgo Software Inc. (Canada) www.highgo.ca
Hello David, Some feedback about v3: In the doc I find TABLEACCESSMETHOD quite hard to read. Use TABLEAM instead? Also, the next entry uses lowercase (tablespace), why change the style? Remove space after comma in help string. I'd use the more readable TABLEAM in the help string rather than the mouthful. It looks that the option is *silently* ignored when creating a partitionned table, which currently results in an error, and not passed to partitions, which would accept them. This is pretty weird. I'd suggest that the table am option should rather by changing the default instead, so that it would apply to everything relevant implicitely when appropriate. About tests : They should also trigger failures, eg "--table-access-method=no-such-table-am", to be added to the @errors list. I do not understand why you duplicated all possible option entry. Test with just table access method looks redundant if the feature is make to work orthonogonally to partitions, which should be the case. > By the way, I saw the same style for other variables, such as > escape_tablespace, should this be fixed as well? Nope, let it be. -- Fabien.
Thanks a lot for the comments, Fabien. > Some feedback about v3: > > In the doc I find TABLEACCESSMETHOD quite hard to read. Use TABLEAM > instead? Yes, in this case, *TABLEAM* is easy to read, updated. > Also, the next entry uses lowercase (tablespace), why change the style? The original style is not so consistent, for example, in doc, --partition-method using *NAME*, but --table-space using *tablespace*; in help, --partition-method using *(rang|hash)*, but --tablespace using *TABLESPACE*. To keep it more consistent, I would rather use *TABLEAM* in both doc and help. > Remove space after comma in help string. I'd use the more readable > TABLEAM in the help string rather than the mouthful. Yes the *space* is removed after comma. > > It looks that the option is *silently* ignored when creating a > partitionned table, which currently results in an error, and not > passed to partitions, which would accept them. This is pretty weird. The input check is added with an error message when both partitions and table access method are used. > > I'd suggest that the table am option should rather by changing the > default instead, so that it would apply to everything relevant > implicitely when appropriate. I think this is a better idea, so in v4 patch I change it to something like "set default_table_access_method to *TABLEAM*" instead of using the *using* clause. > > About tests : > > They should also trigger failures, eg > "--table-access-method=no-such-table-am", to be added to the @errors > list. No sure how to address this properly, since the table access method potentially can be *any* name. > > I do not understand why you duplicated all possible option entry. > > Test with just table access method looks redundant if the feature is > make to work orthonogonally to partitions, which should be the case. Only one positive test case added using *heap* as the table access method to verify the initialization. > >> By the way, I saw the same style for other variables, such as >> escape_tablespace, should this be fixed as well? > > Nope, let it be. > -- David Software Engineer Highgo Software Inc. (Canada) www.highgo.ca
Attachment
Hello David, Some feedback about v4. >> It looks that the option is *silently* ignored when creating a partitionned >> table, which currently results in an error, and not passed to partitions, >> which would accept them. This is pretty weird. > The input check is added with an error message when both partitions and table > access method are used. Hmmm. If you take the resetting the default, I do not think that you should have to test anything? AFAICT the access method is valid on partitions, although not on the partitioned table declaration. So I'd say that you could remove the check. >> They should also trigger failures, eg >> "--table-access-method=no-such-table-am", to be added to the @errors list. > No sure how to address this properly, since the table access method > potentially can be *any* name. I think it is pretty unlikely that someone would chose the name "no-such-table-am" when developing a new storage engine for Postgres inside Postgres, so that it would make this internal test fail. There are numerous such names used in tests, eg "no-such-database", "no-such-command". So I'd suggest to add such a test to check for the expected failure. >> I do not understand why you duplicated all possible option entry. >> >> Test with just table access method looks redundant if the feature is make >> to work orthonogonally to partitions, which should be the case. > Only one positive test case added using *heap* as the table access method to > verify the initialization. Yep, only "heap" if currently available for tables. -- Fabien.
Again, thanks a lot for the feedback. On 2020-12-02 12:03 p.m., Fabien COELHO wrote: > > Hello David, > > Some feedback about v4. > >>> It looks that the option is *silently* ignored when creating a >>> partitionned table, which currently results in an error, and not >>> passed to partitions, which would accept them. This is pretty weird. >> The input check is added with an error message when both partitions >> and table access method are used. > > Hmmm. If you take the resetting the default, I do not think that you > should have to test anything? AFAICT the access method is valid on > partitions, although not on the partitioned table declaration. So I'd > say that you could remove the check. Yes, it makes sense to remove the *blocking* check, and actually the table access method interface does work with partitioned table. I tested this/v5 by duplicating the heap access method with a different name. For this reason, I removed the condition check as well when applying the table access method. > >>> They should also trigger failures, eg >>> "--table-access-method=no-such-table-am", to be added to the @errors >>> list. >> No sure how to address this properly, since the table access method >> potentially can be *any* name. > > I think it is pretty unlikely that someone would chose the name > "no-such-table-am" when developing a new storage engine for Postgres > inside Postgres, so that it would make this internal test fail. > > There are numerous such names used in tests, eg "no-such-database", > "no-such-command". > > So I'd suggest to add such a test to check for the expected failure. The test case "no-such-table-am" has been added to the errors list, and the regression test is ok. > >>> I do not understand why you duplicated all possible option entry. >>> >>> Test with just table access method looks redundant if the feature is >>> make to work orthonogonally to partitions, which should be the case. >> Only one positive test case added using *heap* as the table access >> method to verify the initialization. > > Yep, only "heap" if currently available for tables. > Thanks, -- David Software Engineer Highgo Software Inc. (Canada) www.highgo.ca
Attachment
Hello Justin, > src/test/regress/sql/create_am.sql:CREATE ACCESS METHOD heap2 TYPE TABLE HANDLER heap_tableam_handler; > ... > src/test/regress/sql/create_am.sql:DROP ACCESS METHOD heap2; > Or maybe using SET default_tablespace instead of modifying the CREATE sql. > That'd need to be done separately for indexes, and RESET after creating the > tables, to avoid accidentally affecting indexes, too. Why should it not affect indexes? > @Fabien: I think the table should be created and populated within the same > transaction, to allow this optimization in v13 to apply during the > "initialization" phase. > c6b92041d Skip WAL for new relfilenodes, under wal_level=minimal. Possibly. This would be a change of behavior: currently only filling tables is under an explicit transaction. That would be a matter for another patch, probably with an added option. As VACUUM is not transaction compatible, it might be a little bit tricky to add such a feature. Also I'm not sure about some constraint declarations. ISTM that I submitted a patch a long time ago to allow "()" to control transaction from the command line, but somehow it got lost or rejected. I redeveloped it, see attached. I cannot see reliable performance improvement by playing with (), though. -- Fabien.
Attachment
On Sun, Dec 27, 2020 at 09:14:53AM -0400, Fabien COELHO wrote: > > src/test/regress/sql/create_am.sql:CREATE ACCESS METHOD heap2 TYPE TABLE HANDLER heap_tableam_handler; > > ... > > src/test/regress/sql/create_am.sql:DROP ACCESS METHOD heap2; > > > Or maybe using SET default_tablespace instead of modifying the CREATE sql. > > That'd need to be done separately for indexes, and RESET after creating the > > tables, to avoid accidentally affecting indexes, too. > > Why should it not affect indexes? I rarely use pgbench, and probably never looked at its source before, but I saw that it has a separate --tablespace and --index-tablespace, and that --tablespace is *not* the default for indexes. So if we changed it to use SET default_tablespace instead of amending the DDL sql, we'd need to make sure the SET applied only to the intended CREATE command, and not all following create commands. In the case that --index-tablespace is not specified, it would be buggy to do this: SET default_tablespace=foo; CREATE TABLE ... CREATE INDEX ... CREATE TABLE ... CREATE INDEX ... ... -- Justin PS. Thanks for patching it to work with partitioned tables :)
>> tablespace is an extraneous word ?
Thanks a lot for pointing this out. I will fix it in next patch once get all issues clarified.
On Sun, Dec 27, 2020 at 09:14:53AM -0400, Fabien COELHO wrote:src/test/regress/sql/create_am.sql:CREATE ACCESS METHOD heap2 TYPE TABLE HANDLER heap_tableam_handler; ... src/test/regress/sql/create_am.sql:DROP ACCESS METHOD heap2;
Do you suggest to add a new positive test case by using table access method *heap2* created using the existing heap_tableam_handler?
>> If you found pre-existing inconsistencies/errors/deficiencies, I'd suggest to >> fix them in a separate patch. Typically those are small, and you can make them >> 0001 patch. Errors might be worth backpatching, so in addition to making the >> "feature" patches small, it's good if they're separate. >> Like writing NAME vs TABLESPACE. Or escape vs escapes. I will provide a separate small patch when fixing the *tablespace* typo mention above. Can you help to clarity which releases or branches need to be back patched?
Or maybe using SET default_tablespace instead of modifying the CREATE sql. That'd need to be done separately for indexes, and RESET after creating the tables, to avoid accidentally affecting indexes, too.Why should it not affect indexes?I rarely use pgbench, and probably never looked at its source before, but I saw that it has a separate --tablespace and --index-tablespace, and that --tablespace is *not* the default for indexes. So if we changed it to use SET default_tablespace instead of amending the DDL sql, we'd need to make sure the SET applied only to the intended CREATE command, and not all following create commands. In the case that --index-tablespace is not specified, it would be buggy to do this: SET default_tablespace=foo; CREATE TABLE ... CREATE INDEX ... CREATE TABLE ... CREATE INDEX ... ...
If this `tablespace` issue also applies to `table-access-method`, yes, I agree it could be buggy too. But, the purpose of this patch is to provide an option for end user to test a newly created table access method. If the the *new* table access method hasn't fully implemented all the interfaces yet, then no matter the end user use the option provided by this patch or the GUC parameter, the results will be the same.
>+ " create tables with using specified table access method,\n" In my opinion, this sentence should be "create tables with specified table access method" or "create tables using specifiedtable access method". "create tables with specified table access method" may be more consistent with other options.
On 2021-01-09 5:44 a.m., youichi aramaki wrote: >> + " create tables with using specified table access method,\n" > In my opinion, this sentence should be "create tables with specified table access method" or "create tables using specifiedtable access method". > "create tables with specified table access method" may be more consistent with other options. Thank you Youichi. I will change it to "create tables with specified table access method" in next patch. -- David Software Engineer Highgo Software Inc. (Canada) www.highgo.ca
Hi, `v6-0001-add-table-access-method-as-an-option-to-pgbench` fixed the wording problems for pgbench document and help as they were pointed out by Justin and Youichi. `0001-update-tablespace-to-keep-document-consistency` is trying to make the *tablespace* to be more consistent in pgbench document. Thank you, On 2021-01-14 3:51 p.m., David Zhang wrote: > On 2021-01-09 5:44 a.m., youichi aramaki wrote: > >>> + " create tables with using specified table access >>> method,\n" >> In my opinion, this sentence should be "create tables with specified >> table access method" or "create tables using specified table access >> method". >> "create tables with specified table access method" may be more >> consistent with other options. > > Thank you Youichi. I will change it to "create tables with specified > table access method" in next patch. > -- David Software Engineer Highgo Software Inc. (Canada) www.highgo.ca
Attachment
Hi, On 2020-11-25 12:41:25 +0900, Michael Paquier wrote: > On Tue, Nov 24, 2020 at 03:32:38PM -0800, David Zhang wrote: > > But, providing another option for the end user may not be a bad idea, and it > > might make the tests easier at some points. > > My first thought is that we have no need to complicate pgbench with > this option because there is a GUC able to do that, but we do that for > tablespaces, so... No objections from here. I think that objection is right. All that's needed to change this from the client side is to do something like PGOPTIONS='-c default_table_access_method=foo' pgbench ... I don't think adding pgbench options for individual GUCs really is a useful exercise? Greetings, Andres Freund
On Fri, Jan 15, 2021 at 01:22:45PM -0800, Andres Freund wrote: > I think that objection is right. All that's needed to change this from > the client side is to do something like > PGOPTIONS='-c default_table_access_method=foo' pgbench ... > > I don't think adding pgbench options for individual GUCs really is a > useful exercise? Yeah. Looking at the latest patch, it just uses SET default_table_access_method to achieve its goal and to bypass the fact that partitions don't support directly the AM clause. So I agree to mark this patch as rejected and move on. One thing that looks like an issue to me is that PGOPTIONS is not listed in the section for environment variables on the docs of pgbench. 5aaa584 has plugged in a lot of holes, but things could be improved more, for more clients, where it makes sense of course. -- Michael
Attachment
On 2021-01-15 1:22 p.m., Andres Freund wrote: > Hi, > > On 2020-11-25 12:41:25 +0900, Michael Paquier wrote: >> On Tue, Nov 24, 2020 at 03:32:38PM -0800, David Zhang wrote: >>> But, providing another option for the end user may not be a bad idea, and it >>> might make the tests easier at some points. >> My first thought is that we have no need to complicate pgbench with >> this option because there is a GUC able to do that, but we do that for >> tablespaces, so... No objections from here. > I think that objection is right. All that's needed to change this from > the client side is to do something like > PGOPTIONS='-c default_table_access_method=foo' pgbench ... Yeah, this is a better solution for me too. Thanks a lot for all the feedback. > I don't think adding pgbench options for individual GUCs really is a > useful exercise? > > Greetings, > > Andres Freund -- David Software Engineer Highgo Software Inc. (Canada) www.highgo.ca