Re: Problems with MemoryContextSwitchTo ()

From: Yessica Brinkmann <brinkmann(dot)yessica(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Problems with MemoryContextSwitchTo ()
Date: 2020-09-17 10:46:05
Message-ID: -8uonvrjr4pbt-spdsnx7rniy6-29cn84l7is9ry1nr4e5x9edmfdn22cqnw7wxvemwbb-yzsmqe3g46p1em6l7u-3r7iqjrgff8rz0fpuqa8wiqq5ohsb6t45ntftixb4xn9qrx2-kg0lg6ddou9w.1600339565497@email.android.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<br><br>Good Morning. Thank you so much for the answers. Now I have to go to work, but when I come back I will be looking at the answers in detail, and I will answer. Unfortunately I have to work and study as well, so right now I can't see the answers in detail.<br>Best regards,<br>Yessica Brinkmann. <br><div class="quote" style="line-height: 1.5"><br><br>-------- Mensaje original --------<br>Asunto: Re: Problems with MemoryContextSwitchTo ()<br>De: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com><br>Para: Yessica Brinkmann <brinkmann(dot)yessica(at)gmail(dot)com><br>CC: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org><br><br><br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">čt 17. 9. 2020 v 6:09 odesílatel Pavel Stehule &lt;<a href="mailto:pavel(dot)stehule(at)gmail(dot)com">pavel(dot)stehule(at)gmail(dot)com</a>&gt; napsal:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">čt 17. 9. 2020 v 3:16 odesílatel Yessica Brinkmann &lt;<a href="mailto:brinkmann(dot)yessica(at)gmail(dot)com" target="_blank">brinkmann(dot)yessica(at)gmail(dot)com</a>&gt; napsal:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">
<span lang="en"><span title="">Good night,</span><br><span title="">Thank you very much for the answer.</span><br><span title="">Excuse me please just answered, I was at my job.</span><br><span title="">And yes, I get the results of the list with SPI_exec.</span><br><span title="">And I am also using SPI_finish ().</span> <span title="">But I save the results of the previous query in the array idxcd-&gt;
varattnnames.</span><br><span title="">And in the second foreach it should print me the values that I got in the query, since I print the values of idxcd-&gt; varattnnames, but it is printing null.</span><br><span title="">And I think the memory context switch is fine too, so I really don&#39;t know why it prints null to me.</span><br><span title="">I will greatly appreciate a help please.</span> <span title="">I can&#39;t really understand why it prints null in the second foreach, even though I already tried various changes.</span><br></span></div></blockquote><br></div><div class="gmail_quote">do you use Postgres with active assertions ?</div><div class="gmail_quote"><br></div><div class="gmail_quote">postgres=# show debug_assertions ;<br>┌──────────────────┐<br>│ debug_assertions │<br>╞══════════════════╡<br>│ on               │<br>└──────────────────┘<br>(1 row)<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">maybe you somewhere allocate less memory then it is necessary and some memset rewrites memory with your data. When you have a problem with memory, then you should to very carefully check a) if memory is allocated in good context, b) if memory was allocated enough (sometimes I just allocated x + 100000 for testing).</div><div class="gmail_quote"><br></div><div class="gmail_quote">Can you write a reproducer ? code that I can check at my home. Postgres is pretty complex system, and it is hard to fix some issue without access to code</div><div class="gmail_quote"><br></div></div></blockquote><div><br></div><div>This is some messy in your code</div><div><br></div><div><span style="font-family:monospace">MemoryContext oldContext = MemoryContextSwitchTo( outerContext );<br> MemoryContextSwitchTo( oldContext ); <br></span></div><div><br></div><div>Unfortunately, your code is not well structured - it is hard to read it. One hint - if you find an issue - try to reduce lines of your code which is possible until you reproduce this issue or until you understand this issue.</div><div><br></div><div>The sequence of statements is a little bit obscure :)</div><div><br></div><div><span style="font-family:monospace">initStringInfo( &amp;query );</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace"> */<br> if( cols.len &gt; 0 )<br> {<br> initStringInfo(&amp;cols);<br> } /*IF col.len&gt;0*/</span></div><div><br></div><div>Instead <br></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">foreach( cell, candidates ) /* foreach cell in candidates */<br> {<br></span> <span style="font-family:monospace"><br> int i;<br></span> <span style="font-family:monospace"><br></span> <span style="font-family:monospace"><br></span> <span style="font-family:monospace"><br>    /*elog (INFO, &quot;Ingresando a foreach&quot;);*/<br> idxcd = (IndexCandidate*)lfirst( cell );<br></span> <span style="font-family:monospace"><br> if (idxcd == NULL) {<br>            elog( INFO, &quot;idxcd IS NULL&quot; );<br>            continue; /* Or is that fatal enough to break instead? */<br>        }</span></div><div><br></div><div><br></div><div>you can write<br></div><div><br></div><div><span style="font-family:monospace">idxcd = (IndexCandidate *) linitial(candidates);</span></div><div><br></div><div>The problem in your example is fact so it is a mix of copy/paste fragments. I wrote similar code, and almost everyone I know (when I started). But it is not possible to fix this code - start from scratch. The code must be readable (every time). And when I write code inside some complex environment (like Postgres is), I write code in very small fragments, in very small steps, and every time I try to compile, restart and check the result. Then I know what line, or what statement is the problem. <br></div><div><br></div><div>Regards</div><div><br></div><div>Pavel<br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span lang="en"></span><div><span lang="en"><span title="">Best regards,</span></span></div><div><span lang="en"><span title="">Yessica Brinkmann<br></span></span></div>

</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El mié., 16 sept. 2020 a las 9:16, Pavel Stehule (&lt;<a href="mailto:pavel(dot)stehule(at)gmail(dot)com" target="_blank">pavel(dot)stehule(at)gmail(dot)com</a>&gt;) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">st 16. 9. 2020 v 15:09 odesílatel Yessica Brinkmann &lt;<a href="mailto:brinkmann(dot)yessica(at)gmail(dot)com" target="_blank">brinkmann(dot)yessica(at)gmail(dot)com</a>&gt; napsal:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Well, the fact is that I have a function called get_columnnames, which in the second foreach, is printing the values of idxcd-&gt; varattnnames [i] the null value. This is the error. </blockquote><div><br></div><div>How you get this list? It is result of SPI_exec*** ?<br></div><div><br></div><div>There is SPI_finish(), that cleaning a memory used by SPI interface, and theoretically it can clean result of previous query.</div><div><br></div><div>Regards</div><div><br></div><div>Pavel</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="line-height:1.5"><br><br>-------- Mensaje original --------<br>Asunto: Re: Problems with MemoryContextSwitchTo ()<br>De: Pavel Stehule <u></u><br>Para: Yessica Brinkmann <u></u><br>CC: pgsql-general <u></u><br><br><br type="attribution"><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">st 16. 9. 2020 v 13:32 odesílatel Yessica Brinkmann &lt;<a href="mailto:brinkmann(dot)yessica(at)gmail(dot)com" target="_blank">brinkmann(dot)yessica(at)gmail(dot)com</a>&gt; napsal:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">
<span lang="en"><span title="">Good Morning.</span><br></span><div><span lang="en"><span title="">I will greatly appreciate a help please on this subject.</span> <span title="">I actually did several tests already and tried a lot to fix it myself.</span> <span title="">But I am not able to.</span> <span title="">And I really need to know this in order to finish my university thesis.</span> <span title="">If someone can help me please.</span><br></span></div><div>Best regards,</div><div>Yessica Brinkmann<br></div></div></blockquote><div><br></div><div>please, can you attach your code, and can you show the error message? <br></div><div><br></div><div>It is hard to say what is the problem from your mail?</div><div><br></div><div>Regards</div><div><br></div><div>Pavel<br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div><div><span lang="en"></span></div>

<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El mié., 16 sept. 2020 a las 0:42, Yessica Brinkmann (&lt;<a href="mailto:brinkmann(dot)yessica(at)gmail(dot)com" target="_blank">brinkmann(dot)yessica(at)gmail(dot)com</a>&gt;) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">
<table cellpadding="0"><tbody><tr><td><br></td><td><br></td><td>
Hello.<br>
I think several of you will already remember me. I&#39;m the one with the IndexAdviser topic. Only that I changed my email address.<br>
As you may recall, I am doing my thesis on the subject of IndexAdviser modifications.<br>
I really appreciate the help they have given me in various Postgresql groups.<br>
Well, I was really nearing the end of the programming part of the
thesis, when I had a problem to be able to compile my program in a
moment, and by accident some lines of source code were moved.<br>
And for this reason, I think I have problems again with the context
switch issue, since at some point my context switch stopped working for
me, I think because of the issue that some lines of source code were
moved.<br>
Well, the fact is that I have a function called get_columnnames, which
in the second foreach, is printing the values of idxcd-&gt;
varattnnames [i] the null value.<br>
This second foreach, I only do it to test if the data is really saved well and if I can recover it properly.<br>
And since the data is not retrieved properly, or is not saved properly,
in the following functions of my program, the value of idxcd-&gt;
varattnnames [i] continues to appear as null.<br>
I will appreciate a lot please help, if you can tell me please why the
function prints null in the values of idxcd-&gt; varattnnames [i], in
the second foreach, if it is due to an error in the context switch, or
why it could be .<br>
<div><div id="gmail-m_-882624099522786493gmail-m_-4765376118179730423gmail-m_9008552883760584857gmail-m_6085642464088391972gmail-m_-1533817038986493541gmail-m_8308262266088241857gmail-tw-target"><div id="gmail-m_-882624099522786493gmail-m_-4765376118179730423gmail-m_9008552883760584857gmail-m_6085642464088391972gmail-m_-1533817038986493541gmail-m_8308262266088241857gmail-kAz1tf"><div id="gmail-m_-882624099522786493gmail-m_-4765376118179730423gmail-m_9008552883760584857gmail-m_6085642464088391972gmail-m_-1533817038986493541gmail-m_8308262266088241857gmail-tw-target-text-container"><pre id="gmail-m_-882624099522786493gmail-m_-4765376118179730423gmail-m_9008552883760584857gmail-m_6085642464088391972gmail-m_-1533817038986493541gmail-m_8308262266088241857gmail-tw-target-text" style="text-align:left" dir="ltr"><span lang="en">I send my function as an attachment.</span></pre></div></div></div></div>

<br>
Best regards,<br>
Yessica Brinkmann.

</td></tr></tbody></table>

</div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div></blockquote></div></div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div></div>
</blockquote></div>

Attachment Content-Type Size
unknown_filename text/html 12.8 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2020-09-17 11:08:06 Re: PostgreSQL processes use large amount of private memory on Windows
Previous Message Øystein Kolsrud 2020-09-17 09:19:07 PostgreSQL processes use large amount of private memory on Windows